Several common encryption functions in PHP and common encryption functions in PHP

Source: Internet
Author: User
Tags crypt format message md5 hash sha1 encryption alphanumeric characters

Several common encryption functions in PHP and common encryption functions in PHP

MD5 encryption:

String md5 (string $ str [, bool $ raw_output = false])

1. by default, md5 () returns a hash value in the hexadecimal format of 32 characters. It accepts two parameters: the first is the string to be encrypted, and the second is the Boolean value of raw_output, the default value is false. If it is set to true, md5 () will return the original 16-bit binary message digest.

2. md5 () is one-way encryption, and there is no reverse decryption algorithm. However, it can still be used to crack common strings through methods such as collection, enumeration, and collision.

<? Php $ username = 'jellybool '; $ password = 'jellybool. com ';/* encrypt strings in md5 mode */echo md5 ($ username); echo "

Crypt encryption:

String crypt (string $ str [, string $ salt])

1. crypt () accepts two parameters: the first is the string to be encrypted, and the second is the salt value (that is, the encrypted interference value. If not provided, it is automatically generated by PHP by default ); returns the hash string or a string less than 13 characters, which is used to distinguish the salt value.
2. crypt () is one-way encryption, which is the same as md5.

<? Php $ password = 'jellybool. com '; echo crypt ($ password); // output: $1 $ Fe0.qr5. $ WOhkI4/5VPo7n7TnXHh5K/* the eight characters between the second $ and the third $ are generated by PHP and changed once every refresh */echo "

Sha1 encryption:

String sha1 (string $ str [, bool $ raw_output = false]

1. unlike md5, sha1 () returns a 40-character hash value by default. The input parameter is of the same nature, and the first is an encrypted string, the second is a Boolean value of raw_output. The default value is false. If it is set to true, sha1 () will return the original 20-bit original format message digest.
2. sha1 () is also single-line encryption, with no reverse decryption algorithm

<? Php $ my_intro = "jellybool"; echo sha1 ($ my_intro); // output: c98885c04c1208fd4d0b1dadd3bd2a9ff4d042caecho "

Urlencode encryption:

String urlencode (string $ str)
1. A parameter that is used to pass in the string to be encrypted (usually used to encrypt the URL ),
2. urlencode is bidirectional encryption, which can be encrypted using urldecode (strictly speaking, it is not actually encrypted)
3. returns a string -_. all other non-alphanumeric characters will be replaced with a semicolon (%) followed by two hexadecimal numbers, and spaces will be encoded as the plus sign (+ ).

<? Php // urlencode () is usually used to hide plaintext data in a URL $ my_urlencode = "jellybool.com? Jellybool = true + 4-3% 5 = \&@! "; Echo urlencode ($ my_urlencode); // output: jellybool.com % 3 Fjellybool % 3 Dtrue + % 2B + 4-3% 255% 3D + % 5C % 26 + % 40% 21 echo "

Base64 encryption:

String base64decode (string $ encodeddata)
1. base64_encode () accepts a parameter, that is, the data to be encoded (this is not a string here, because base64 is often used to encode images)
2. base64encode () is bidirectional encryption and can be decrypted using base64decode ().

Echo base64_encode ($ my_intro); echo "

Example of an image:

<? Php/* example of an image app */$ filename = "https://worktile.com/img/index/index_video.png"; $ data = file_get_contents ($ filename); echo base64_encode ($ data ); /* then you can view the source code of the webpage to get a large string of base64, and then restore it with base64_decode () to get the image */

This article was created by JellyBool.

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.