3 Please read the README file for condition of use, before
6 Maurice Gittens <mgittens@gits.nl> January 1997
14 #include <openssl/evp.h>
19 #define INIT_VECTOR "12345678"
22 #define ALG EVP_des_ede3_cbc()
24 static const char *usage = "Usage: example3 [-d] password\n";
26 void do_cipher(char *,int);
28 int main(int argc, char *argv[])
32 do_cipher(argv[1],ENCRYPT);
34 else if ((argc == 3) && !strcmp(argv[1],"-d"))
36 do_cipher(argv[2],DECRYPT);
40 fprintf(stderr,"%s", usage);
47 void do_cipher(char *pw, int operation)
50 char ebuf[BUFLEN + 8];
51 unsigned int ebuflen; /* rc; */
52 unsigned char iv[EVP_MAX_IV_LENGTH], key[EVP_MAX_KEY_LENGTH];
53 /* unsigned int ekeylen, net_ekeylen; */
56 memcpy(iv, INIT_VECTOR, sizeof(iv));
58 EVP_BytesToKey(ALG, EVP_md5(), "salu", pw, strlen(pw), 1, key, iv);
60 EVP_CipherInit(&ectx, ALG, key, iv, operation);
64 int readlen = read(STDIN, buf, sizeof(buf));
77 EVP_CipherUpdate(&ectx, ebuf, &ebuflen, buf, readlen);
79 write(STDOUT, ebuf, ebuflen);
82 EVP_CipherFinal(&ectx, ebuf, &ebuflen);
84 write(STDOUT, ebuf, ebuflen);