29 lines
792 B
PHP
29 lines
792 B
PHP
<?php
|
|
|
|
function encryptAES($data, $key, $iv) {
|
|
$encrypted = openssl_encrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
|
$encrypted = base64_encode($encrypted);
|
|
return $encrypted;
|
|
}
|
|
|
|
function decryptAES($encryptedData, $key, $iv) {
|
|
$encryptedData = base64_decode($encryptedData);
|
|
$decrypted = openssl_decrypt($encryptedData, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
|
return $decrypted;
|
|
}
|
|
|
|
// 加密数据
|
|
$data = 'Hello-World!';
|
|
$key = 'laysensechina000';
|
|
$iv = '1234567890abcdef';
|
|
|
|
$encryptedData = encryptAES($data, $key, $iv);
|
|
echo '加密后的数据:' . $encryptedData;
|
|
|
|
echo '<hr>';
|
|
|
|
// 解密数据
|
|
$decryptedData = decryptAES($encryptedData, $key, $iv);
|
|
echo '解密后的数据:' . $decryptedData;
|
|
|
|
?>
|