This article describes the PHP based on Mcrypt_encrypt and mcrypt_decrypt implementation of string encryption and decryption method. Share to everyone for your reference, specific as follows:
Because of the security considerations, the parameter transmission needs to be encrypted and decrypted, a relatively simple method is directly using PHP functions Mcrypt_encrypt, Mcrypt_decrypt, a cryptographic, a decryption, but the problem has arisen, This encryption process will create some symbols that confuse the URL, and then after the encryption of the encryption characters again processing, and then more than one by one resolution:
$key = "Miyao";//Key
$string = "Jiami"//required encrypted character//
with the encrypted function
$crypttext = Base64_encode (Mcrypt_encrypt ( MCRYPT_RIJNDAEL_256, MD5 ($key), $string, MCRYPT_MODE_CBC, MD5 (MD5 ($key)));
$encrypted =trim ($this->safe_b64encode ($crypttext))//To handle special characters
$key = "Miyao"
$CRYPTTEXTTB =safe_ B64decode ($encrypted)//to the special character parsing
$decryptedtb = RTrim (Mcrypt_decrypt (mcrypt_rijndael_256, MD5 ($key), base64_ Decode ($CRYPTTEXTTB), MCRYPT_MODE_CBC, MD5 (MD5 ($KEY)))//decryption function
//handling special characters public function
Safe_b64encode ($string) {
$data = Base64_encode ($string);
$data = str_replace (Array (' + ', '/', ' = '), array ('-', ' _ ', '), $data);
return $data;
}
Resolves special characters public
function Safe_b64decode ($string) {
$data = str_replace (Array ('-', ' _ '), Array (' + ', '/'), $ string);
$mod 4 = strlen ($data)% 4;
if ($mod 4) {
$data. = substr (' = = = ', $mod 4);
}
Return Base64_decode ($data);
PS: About encryption and decryption interested friends can also refer to the site online tools:
Password Security online detection:
Http://tools.jb51.net/password/my_password_safe
High Strength Password Generator:
Http://tools.jb51.net/password/CreateStrongPassword
MD5 Online Encryption Tool:
Http://tools.jb51.net/password/CreateMD5Password
Thunderbolt, Express, Cyclone URL encryption/decryption tool:
Http://tools.jb51.net/password/urlrethunder
Online hashing/hashing algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt
More about PHP related content to view the site topics: "PHP Encryption Method Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary (including Word,excel, Access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.