Home > Article > Backend Development > Sharing a set of PHP encryption and decryption functions_PHP tutorial
/**
*Function: Decrypt the string
*Parameter 1: The ciphertext to be decrypted
*Parameter 2: Key
*/
function passport_decrypt($str,$key){ //解密函数
$str=passport_key(base64_decode($str),$key);
$tmp='';
for($i=0;$i
$tmp.=$str[++$i] ^ $md5;
}
return $tmp;
}
/**
*Auxiliary function
*/
function passport_key($str,$encrypt_key){
$encrypt_key=md5($encrypt_key);
$ctr=0;
$tmp='';
for($i=0;$i
$tmp.=$str[$i] ^ $encrypt_key[$ctr++];
}
return $tmp;
}
$str='作者:WWW.JB51.NET;
$key='jb51net';
$encrypt=passport_encrypt($str,$key);
$decrypt=passport_decrypt($encrypt,$key);
echo '原文:',$str."