Php uses character variable encryption when registering, logging on, or passing url parameters. The following is a brief introduction: the irreversible encryption function of the php built-in encryption function is: md5 (), crypt ()
Md5 () is used to calculate MD5. Syntax: string md5 (string str );
Crypt () encrypts the string with the standard DES module of UNIX. This is a one-way encryption function and cannot be decrypted. To compare the string, place the first two characters of the encrypted string in the salt parameter, and then compare the encrypted string. Syntax: string crypt (string str, string [salt]);
Reversible encryption: corresponding decryption functions of base64_encode () and urlencode (): base64_decode () and urldecode ()
Base64_encode () encodes the string with MIME BASE64. This encoding method enables smooth transmission of Chinese text or images over the network. The syntax is string base64_encode (string data); its decryption function is: string base64_decode (string encoded_data); returns the original
Urlencode () encodes the string into a URL. For example, a space is changed to a plus sign. Syntax: string urlencode (string str );
Its decryption function is: string urldecode (string str); returns the original
Code:
The code is as follows:
Define ("str", "");
Echo 'md5 encrypted result: '. md5 (str ).'
'; // Md5 encryption
Echo 'Crypt encrypted result: '. crypt (str, str ).'
'; // Crypt encryption
$ Base64encode = base64_encode (str); // base64_encode () encryption
Echo 'base64_encode: '. $ base64encode .'
';
Echo 'base64 _ decode: '. base64_decode ($ base64encode ).'
'; // Base64_decode () decryption
$ Urlencode = urlencode (str); // urlencode () encryption
Echo 'urlencode: '. $ urlencode .'
';
Echo 'urldecode: '. urldecode ($ urlencode ).'
'; // Urldecode () decryption
?>
The output result is:
The md5 encryption result is: ea796af15c74e90faeba49576fa7984b.
The encrypted result of crypt is: moylczgttyxps.
Base64_encode: xKu9ow =
Base64_decode: the decrypted result is: Mo Jian
Urlencode encrypted result: % C4 % AB % BD % A3
After urldecode is decrypted, the result is: Mo Jian.