4
$\begingroup$

I have been using the openssl function for encrypting data with AES-256-CBC in php. I have been able to encrypt it using an unique IV (by generating with openssl_random_pseudo_bytes)for each new encryption.

But I am struggling with the idea of authenticated encryption with aes cbc. How do I basically authenticate when I am about to decrypt the data?

Do I need to use something like PBKDF2, blowfish or hash_hmac()?

Do I need to hash the key somehow?

Any help is extremely appreciated.

$\endgroup$
3

1 Answer 1

2
$\begingroup$

Basically you would be constructing an AEAD scheme. You will need to perform HMAC over the IV, the ciphertext and possibly over additional associated data (AAD). If you just need to authenticate the ciphertext then you may simply leave out (or leave empty) the AAD - but not the IV during the HMAC function.

Fortunately somebody already thought about standardizing this, so you may simply copy this draft RFC called " Authenticated Encryption with AES-CBC and HMAC-SHA". Obviously having a draft RFC is less optimal than a full RFC with a lot of research, but at least it has undergone some evaluation. It basically formalizes something that already existed in the first place.

Notes:

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.