PHP7.1 mcrypt 替代方案

2021-12-27 00:00:00 encoding decode php mcrypt php-7.1

自 PHP 7.1.0 起,Mcrypt 函数已被弃用.

Mcrypt function has been deprecated as of PHP 7.1.0.

我已弃用的​​字符串编码/解码功能:

My deprecated string encode / decode functions:

$key: secret key
$str: string


$encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $str, MCRYPT_MODE_CBC, md5(md5($key))));

$decoded = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($str), MCRYPT_MODE_CBC, md5(md5($key))), "");

你能提出一些替代方案吗?

Can you suggest some alternatives?

推荐答案

你应该使用 openssl_encrypt 代替.

相关文章