[英]Is mcrypt_encrypt() function not working in PHP 7.2?
我有如下加密代码,它在 PHP 5.6 版中工作。 但它在 PHP 版本 7.2 中不起作用。
**
警告:使用未定义的常量 MCRYPT_RIJNDAEL_128 - 假定为“MCRYPT_RIJNDAEL_128”(这将在 PHP 的未来版本中引发错误)
**
这个有什么选择吗?
$serviceid="2951";
$secretkey = "fQ5FHy0qzM6ljp97";
function pkcs5_pad ($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
function encrypt($plaintext, $key) {
$plaintext = pkcs5_pad($plaintext, 16);
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB);
$ciphertext_base64 = base64_encode($ciphertext);
$ciphertext_base64;
}
$data = $serviceid;
$auth= encrypt($data ,$secretkey);
加密值为AGchNk2xOnHHxhgYv02XJw==
我在 PHP 7.2 中尝试了以下代码
function encrypt($plaintext, $key)
{
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-128-cbc'));
$encrypted = openssl_encrypt($plaintext, 'aes-128-cbc', $key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
但 output 不断变化
我找到了我的查询的解决方案。 请检查以下
function encrypt($plaintext,$key)
{
return base64_encode(openssl_encrypt($plaintext, 'aes-128-ecb', $key, OPENSSL_RAW_DATA));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.