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?