PHP加密解密函数
function encryptDecrypt($key, $string, $decrypt){
if($decrypt){
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "12");
return $decrypted;
}else{
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
return $encrypted;
}
}
使用方法:
echo "加密:".encryptDecrypt('password', '尚锦科技www.nmgsj.shop',0);
echo "<br />解密:".encryptDecrypt('password', 'AvWc0amI3DImdpm3cwjgvWRkZpdzId973ZJCb6uucf4=',1);