I tried to implement a \"very\" simple encryption/decryption example. I need it for a project where I would like to encrypt some user information. I can\'t encrypt the whole
The problem is that AES_cfb128_encrypt
modifies the ivec
(it has to in order to allow for chaining). Your solution is to create a copy of the ivec
and initialize it before each call to AES_cfb128_encrypt
as follows:
const char ivecstr[AES_BLOCK_SIZE] = "goodbyworldkey\0";
unsigned char ivec[AES_BLOCK_SIZE];
memcpy( ivec , ivecstr, AES_BLOCK_SIZE);
Then repeat the memcpy
before your second call to AES_cfb128_encrypt
.
Note 1: Your initial vector was a byte too short, so I put an explicit additional \0
at the end of it. You should make sure all of your strings are of the correct length when copying or passing them.
Note 2: Any code which uses encryption should REALLY avoid using strcpy
or any other copy of unchecked length. It's a hazard.