This article mainly introduces the encryption and decryption methods implemented by php combined with md5, involving PHP string operations and encryption and decryption algorithm implementation skills, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:
Recently, I have found a good thing in the code, combined with the md5 encryption and decryption algorithm. There are few decryption algorithms for php and md5 encryption on the internet. In fact, there is one in the php Manual, just change it. Paste it here and use this algorithm to load a php module mcrypt, otherwise it will not work.
// Encryption function string2secret ($ str) {$ key = "123"; $ td = mcrypt_module_open (MCRYPT_DES, '', 'ECB ',''); $ iv = mcrypt_create_iv (Encrypt ($ 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;} // decrypt function secret2string ($ sec) {$ key = "123"; $ td = mcrypt_module_open (MCRYPT_DES, '', 'ECB ',''); $ iv = mcrypt_create_iv (Encrypt ($ 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 result is 11111111111111111 echo string2secret ("11111111111111111"); // garbled characters are displayed.
Php often uses encryption and decryption functions, such as base64_encode and base64_decode.