Hi, I am using openssl evp api to encrypt / decrypt a file using AES256CBC.
The file is encrypted using the key 'k' and iv 'v' (which were generated using the EVP_BytesToKey()
function, where I provide random bytes of data in the form of salt that I receive from RAND_bytes()
and the password provided by the user, and then using these two, I initialize the encryption context and decrypt the context.
Initialization Function:
int aes_init(unsigned char* pwd, unsigned int pwd_len,EVP_CIPHER_CTX *e_ctx, EVP_CIPHER_CTX *d_ctx) { int i, rounds =5; unsigned char key[32], iv[32], salt[8]; if(!(RAND_bytes(salt,8)))
I plan to implement this scenario:
The user encrypts file A with key k and program IV v. Then, if now the user now wants to decrypt the encrypted file A, he will need the same encryption context, that is, the same key k, the same IV.
So my problem is how can I safely save the key and iv (the same as for encryption) so that I can use it to decrypt the file later.
NOTE. I saw how some commercial encryption products create some kind of keystore for this, any idea how this is done.
Is there any set of recommendations that follow this?
Any suggestion would be greatly appreciated.
Many thanks
source share