$data = "This is an AES crypt demo.";
$privateKey = "5d4bcd5912db00c28e9ce7fd5e9b7f78"; // KEY 16字节用aes-128-cbc,32字节用aes-256-cbc
$iv= "4490d2ded4f2d4ad"; //AES的IV是16个字节
//加密
// $encrypted = openssl_encrypt($data,'aes-128-cbc',$privateKey,0,$iv);
$encrypted = openssl_encrypt($data,'aes-256-cbc',$privateKey,0,$iv);
echo $encrypted,PHP_EOL;
// 解密
$encryptedData = $encrypted;
// $decrypted = openssl_decrypt($encryptedData,'aes-128-cbc',$privateKey,0,$iv);
$decrypted = openssl_decrypt($encryptedData,'aes-256-cbc',$privateKey,0,$iv);
echo($decrypted);
评论(0)