This article illustrates the encryption and decryption method implemented by PHP combined with MD5. Share to everyone for your reference, specific as follows:
Recently in the collation of the code found a good thing, combined with MD5 encryption and decryption algorithm. On the internet about PHP combined with MD5 encryption, decryption algorithm is less than, in fact, PHP manual inside there are, to change the line. In this post, use this algorithm to load a PHP module MCrypt, or not.
/Cryptographic function String2secret ($str) {$key = "123";
$TD = Mcrypt_module_open (Mcrypt_des, ', ' ECB ', ');
$iv = Mcrypt_create_iv (Mcrypt_enc_get_iv_size ($TD), Mcrypt_rand);
$ks = Mcrypt_enc_get_key_size ($TD);
$key = substr (MD5 ($key), 0, $ks);
Mcrypt_generic_init ($TD, $key, $IV);
$secret = Mcrypt_generic ($TD, $STR);
Mcrypt_generic_deinit ($TD);
Mcrypt_module_close ($TD);
return $secret;
}//Decryption function secret2string ($sec) {$key = "123";
$TD = Mcrypt_module_open (Mcrypt_des, ', ' ECB ', ');
$iv = Mcrypt_create_iv (Mcrypt_enc_get_iv_size ($TD), Mcrypt_rand);
$ks = Mcrypt_enc_get_key_size ($TD);
$key = substr (MD5 ($key), 0, $ks);
Mcrypt_generic_init ($TD, $key, $IV);
$string = Mdecrypt_generic ($TD, $sec);
Mcrypt_generic_deinit ($TD);
Mcrypt_module_close ($TD);
Return trim ($string); } Echo secret2string (String2secret ("11111111111111111")); The display result is 11111111111111111 echo string2secret ("11111111111111111"); Display garbled
PHP is often used with the encryption and decryption function, Base64_encode,base64_decode.
More about PHP encryption and decryption related content readers can view the site topics: "PHP encryption Method Summary"
I hope this article will help you with the PHP program design.