我想先加密html数据,然后再保存到数据库中。 这是一个示例html文本:
<p>test data in normal text</p> <p><b>test data in bold text</b></p> <p><i>test data in italics text</i></p> <p><b><i>test data in bold and italics text</i></b><br></p>
谁能帮助我找到解决方案。
答案 0 :(得分:1)
使用可以使用OpenSSL加密
$plaintext = "message to be encrypted";
$cipher = "aes-128-gcm";
if (in_array($cipher, openssl_get_cipher_methods()))
{
$ivlen = openssl_cipher_iv_length($cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv, $tag);
//store $cipher, $iv, and $tag for decryption later
$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, $options=0, $iv, $tag);
echo $original_plaintext."\n";
}
查看以下链接以获取更多详细信息 http://php.net/manual/en/function.openssl-encrypt.php