I have a problem with the openssl_decrypt
function.
Example code:
// mcrypt
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
// OpenSSL
$decrypted = openssl_decrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
The mcrypt_decrypt
function works fine. But openssl_decrypt
returns FALSE
and the following error:
error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
The key is 32 bytes long and the iv 16 bytes.
Does anyone know what's wrong?
The solution to the problem is OPENSSL_RAW_DATA
and OPENSSL_ZERO_PADDING
:
$decrypted = openssl_decrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With