PHP combined with MD5 implementation of encryption and decryption method _php skills

Source: Internet
Author: User
Tags md5 md5 encryption

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.