php一段用于加解密的公共函数
加密
function idcard_encrytp($str)
{
$key = "123456";
$ciphertext_raw = openssl_encrypt($str, "AES-128-CBC", $key, OPENSSL_RAW_DATA,'16bytestring');
$ciphertext = base64_encode($ciphertext_raw);
return $ciphertext;
}
//解密
function idcard_decrytp($ciphertext)
{
$key = "123456";
$ciphertext_raw = base64_decode($ciphertext);
$original_plaintext = openssl_decrypt($ciphertext_raw, "AES-128-CBC", $key, OPENSSL_RAW_DATA,'16bytestring');
return $original_plaintext;
}
可加密可解密,好使