When communicating with the client and the server, there is a common scenario that is passed back and forth through an ID as a URL parameter. Assuming that there is only this ID identified in the business, then a slightly more secure communication is required, and the ID is encrypted and transmitted to the server for decryption. This requires a confidential key from the server, which is used to encrypt and decrypt the key.
The decryption method is as follows: $str is a string that needs to be decrypted, $key is a key of its own definition
//EncryptfunctionENCRYPTSTR ($str,$key){ $block= Mcrypt_get_block_size (' des ', ' ECB '); $pad=$block- (strlen($str) %$block); $str.=str_repeat(CHR($pad),$pad); $enc _str= Mcrypt_encrypt (Mcrypt_des,$key,$str,MCRYPT_MODE_ECB); return Base64_encode($enc _str);}//decryptionfunctionDECRYPTSTR ($str,$key){ $str=Base64_decode($str); $str= Mcrypt_decrypt (Mcrypt_des,$key,$str,MCRYPT_MODE_ECB); $block= Mcrypt_get_block_size (' des ', ' ECB '); $pad=Ord($str[($len=strlen($str))-1]); return substr($str, 0,strlen($str) -$pad);}
It is worth mentioning that:
If the URL is applied to the ID of this scene, then after the encryption is Base64 encoding, it is recommended to UrlEncode (), remove the + number of the effect.
PHP uses a custom key, the method of data encryption and decryption