请教:微信消息加密算法中用openssl_decrypt替换mcrypt_module 失败的问题
加密数据:”kJZVt79WAWoSyq/e3GAobcAr0bIXss0/MC1zoSzG/oVQQUYn0XMcK2vVUtDSuaRAVQ5V/kdU2LBY7KkK/QSgnEakj94ENVIIT4ej+zBt25RkSPPcwjJJfJJc9c7UGqG3J9YcCDYc0hhdx0zm9ilYDTTBpN7AazBoMcOgn7LECv+SQrZ4/cA2IPjcD/2mvKHy6zL8wTYiQUaY2IVihKfwfZUpkZWBk3Zn/XJeDP5y36mxrKkC2ql7BxLQd5Q2CCkYy+5CRBnwtyO1spgY1p9FQJKX1ZCIzbPB439gxebBQa0=”
key:”uXchiSqrsWLBekIXafSMvTFEg4FbibQxX1Sg3BiNgeu”
mcrypt_module 解密方法:
try {
$key = base64_decode($key . "=");
//使用BASE64对需要解密的字符串进行解码
$ciphertext_dec = base64_decode($encrypted);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($key, 0, 16);
mcrypt_generic_init($module, $key,$iv);
//解密
$decrypted = mdecrypt_generic($module, $ciphertext_dec);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
dump($decrypted);
} catch (Exception $e) {
return $e->getMessage();
}
openssl_decryp解密方法:
try {
$key = base64_decode($key . "=");
$iv = substr($key, 0, 16);
// //使用BASE64对需要解密的字符串进行解码
$ciphertext_dec = base64_encode($encrypted);
$decrypted = openssl_decrypt($ciphertext_dec,'AES-128-CBC',$key,OPENSSL_ZERO_PADDING,$iv);
dump($decrypted);
} catch (Exception $e) {
return $e->getMessage();
}
执行mcrypt_module解密成功,但是执行openssl_decryp解密返回fasle,有哪位兄弟有遇到过类似情况的吗
推荐文章: