-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdes.txt
51 lines (31 loc) · 2.26 KB
/
des.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
If Triple DES is desired (in addition to regular DES), the label TRIPLEDES must be defined, usually by a -D option on the compiler command line.
For the fastest operation, data used by the package is packed one bit per byte. Each byte must be either 0 or 1. The results will be highly anomalous if this is not the case.
To DES encrypt or decrypt, first declare an object of the des encryption class:
des crypto;
To Triple DES encrypt or decrypt, first declare an object of the triple_des encryption class:
triple_des crypto;
If you have a 56-bit key, you can initialize a des object to encrypt and decrypt with the specified key by calling a member function:
crypto.initialize(key);
const unsigned char key[DES_KEY_SIZE];
56-bit encryption and decryption
key, packed one bit per byte (each
byte must be either 0 or 1)
If you have a 168-bit key, you can initialize a triple_des object to encrypt and decrypt with the specified key by calling a member function:
crypto.initialize(key);
const unsigned char key[3*DES_KEY_SIZE];
168-bit encryption and decryption
key, packed one bit per byte (each
byte must be either 0 or 1)
Alternatively, you may generate a key and initialize the object with a password:
crypto.password(p);
const char *p; pointer to nul-terminated password
The password may be any length (except zero), but only the first 32 characters will be used for regular DES, and only the first 48 characters will be used for Triple DES. It may contain any characters except nuls. It is case-sensitive; i.e., passwords that differ only in capitalization will produce different keys.
Then to encrypt or decrypt a block of 64 bits, call the member functions:
crypto.encrypt(data);
crypto.decrypt(data);
unsigned char data[DES_DATA_SIZE];
64-bit block of data to be
encrypted or decrypted, packed one
bit per byte (each byte must be
either 0 or 1)
The encrypted or decrypted data is written back into the same buffer in the same format (one bit per byte).