Hello, EVP_EncryptInit.pod includes an example for "General encryption, decryption function example using FILE I/O and RC2". The code doesn't compile right away, though, (a few variables are not prototyped or declared) and needs a few minor tweaks (see attached).
-Jan
diff -burN openssl-0.9.8i.orig/doc/crypto/EVP_EncryptInit.pod openssl-0.9.8i/doc/crypto/EVP_EncryptInit.pod --- openssl-0.9.8i.orig/doc/crypto/EVP_EncryptInit.pod 2005-04-15 12:01:35.000000000 -0400 +++ openssl-0.9.8i/doc/crypto/EVP_EncryptInit.pod 2008-12-27 14:35:33.000000000 -0500 @@ -458,8 +458,9 @@ int do_crypt(FILE *in, FILE *out, int do_encrypt) { /* Allow enough space in output buffer for additional block */ - inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; + unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; int inlen, outlen; + EVP_CIPHER_CTX ctx; /* Bogus key and IV: we'd normally set these from * another source. */ @@ -467,7 +468,7 @@ unsigned char iv[] = "12345678"; /* Don't set key or IV because we will modify the parameters */ EVP_CIPHER_CTX_init(&ctx); - EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt); + EVP_CipherInit_ex(&ctx, EVP_rc2_cbc(), NULL, NULL, NULL, do_encrypt); EVP_CIPHER_CTX_set_key_length(&ctx, 10); /* We finished modifying parameters so now we can set key and IV */ EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt);
pgpEOtrTg6v7o.pgp
Description: PGP signature