Introduction to the md5, crypt, and base64_encode encryption functions of php

Source: Internet
Author: User
Tags crypt php define
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:

 '; // Md5 encrypted echo 'Crypt encrypted result:'. crypt (str, str ).'
'; // Crypt encryption $ base64encode = base64_encode (str); // base64_encode () encrypted echo 'base64 _ encode:'. $ base64encode .'
'; Echo 'base64 _ decode:'. base64_decode ($ base64encode ).'
'; // Base64_decode () decryption $ urlencode = urlencode (str); // urlencode () encrypted echo 'urlencode encrypted result:'. $ 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.



For more information about the use of php encryption functions such as md5, crypt, and base64_encode, see the Chinese PHP website!

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.