【发布时间】:2020-11-05 12:25:05
【问题描述】:
我尝试了以下代码
<?PHP
$encrypt_method = "AES-128-CBC";
$secret_key = 'iuiuiui';
$secret_iv = '1234567891234567';
$string="keeri";
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
echo "encrypt----)";
echo $output ;
echo "decrypt---";
$output1 = openssl_decrypt($string, $encrypt_method, $key, 0, $iv);
echo $output1;
?>
得到以下输出
encrypt----)3BR54C8qvhHG3e4Lgry4uw==decrypt----)
解密字符串 ($output1) 为空。
【问题讨论】: