In the development of the application process we often involve a number of links or parameters or the encryption and decryption of cookies, because PHP itself provides MD5 function is not reversible, so MD5 only apply to similar password encryption, and cookie encryption has limitations, the following provides a cryptographic decryption function method, For everyone's reference:
<?PhpCryptographic functionsfunctionPassport_encrypt($txt,$key) {Srand((Double)Microtime() * 1000000);$encrypt _key=Md5(Rand(0, 32000));$ctr= 0;$tmp= ‘‘;For($i= 0;$i<Strlen($txt);$i++) {$ctr=$ctr==Strlen($encrypt _key) ? 0 :$ctr;$tmp.=$encrypt _key[$ctr]. ($txt[$i] ^$encrypt _key[$ctr++]);}ReturnBase64_encode(Passport_key($tmp,$key));}Decryption functionfunctionPassport_decrypt($txt,$key) {$txt=Passport_key(Base64_decode($txt),$key);$tmp= ‘‘;For($i= 0;$i<Strlen($txt);$i++) {$MD 5=$txt[$i];$tmp.=$txt[++$i] ^$MD 5;}return $tmp ;}function Passport_key $txt , $encrypt _key) Span class= "PLN" > { $encrypt _key = Md5 $encrypt _key= 0; $tmp = "; for ($i = 0; $i < strlen ($txt); $i + +) {$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr; $tmp. = $txt [$i] ^ $encrypt _key[$ctr + +];} return $tmp;} echo Passport_encrypt (' Ender Rabbit ', ' andetu '); Echo ' <br> '; Echo passport_decrypt (' ubge+lfwvlmh4wc9db8ejfxf ', ' Andetu ') );
php with parameter reversible cryptographic decryption function, can be used for encryption and decryption of cookies