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

Source: Internet
Author: User
Tags crypt

Irreversible encryption functions: 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:
Copy codeThe Code is as follows:
<? Php
Define ("str", "");
Echo 'md5 encrypted result: '. md5 (str).' <br> '; // md5 encrypted
Echo 'crypt encrypted result: '. crypt (str, str).' <br> '; // crypt encrypted
$ Base64encode = base64_encode (str); // base64_encode () Encryption
Echo 'base64_encode: '. $ base64encode.' <br> ';
Echo 'base64_decode: '. base64_decode ($ base64encode).' <br> '; // base64_decode () Decryption result
$ Urlencode = urlencode (str); // urlencode () Encryption
Echo 'urlencode: '. $ urlencode.' <br> ';
Echo 'urldecode: '. urldecode ($ urlencode).' <br> '; // urldecode () Decryption result
?>

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.

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.