函数名称:openssl_encrypt()
适用版本:PHP 5 >= 5.3.0, PHP 7
函数描述:openssl_encrypt() 函数用于对数据进行加密。
语法:string openssl_encrypt ( string $data , string $method , string $password [, int $options = 0 [, string $iv = "" [, string &$tag = NULL [, string $aad = "" [, int $tag_length = 16 ]]]]] )
参数说明:
返回值:加密后的数据,以字符串形式返回。
示例:
$data = "Hello, world!";
$method = "AES-256-CBC";
$password = "myPassword";
$options = 0;
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$encrypted = openssl_encrypt($data, $method, $password, $options, $iv);
echo "加密后的数据:".$encrypted."\n";
$decrypted = openssl_decrypt($encrypted, $method, $password, $options, $iv);
echo "解密后的数据:".$decrypted."\n";
输出结果:
加密后的数据:5B7n0m0qMF0nXbU2XnU0xY0oXf7n3V5l1G6q5u5n4y1=
解密后的数据:Hello, world!
注意事项: