问题
The function below correctly decrypt the data in php5
function decrypt_mcrypt($key, $str) {
$str = base64_decode($str);
$iv = substr($str, 0, 16);
$str = substr($str, 16);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_CFB, $iv);
}
I tried to use openssl instead of mcrypt (in php7), but got garbage on the output.
function decrypt_openssl($key, $str) {
$str = base64_decode($str);
$iv = substr($str, 0, 16);
$str = substr($str, 16);
return openssl_decrypt($str, 'AES-256-CFB', $key, OPENSSL_RAW_DATA, $iv);
}
What could be the problem?
回答1:
openssl_decrypt
uses PKCS#5 padding, where as mcrypt
pads messages with zeros.
Try using the OPENSSL_ZERO_PADDING
option when using openssl_decrypt
as per the docs.
来源:https://stackoverflow.com/questions/48924727/decrypt-aes-256-cfb-in-php-with-openssl-instead-mcrypt