函数
function encryptDecrypt($string, $decrypt, $key='lulublog'): string
{
if($decrypt){
return rtrim(@mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "12");
}else{
return base64_encode(@mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
}
}
测试
$encrypt = encryptDecrypt('lulublog欢迎您',0);
var_dump($encrypt);
$decrypt = encryptDecrypt($encrypt,1);
var_dump($decrypt);