Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mcrypt_decrypt, openssl_decrypt and 0x06065064 EVP_DecryptFinal error

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?

like image 946
schramster Avatar asked Oct 19 '25 05:10

schramster


1 Answers

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);
like image 200
schramster Avatar answered Oct 21 '25 20:10

schramster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!