Several common cryptographic functions in PHP _php techniques

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

MD5 Encryption:

String MD5 (string $str [, bool $raw _output = false])

1.MD5 () returns a hash value in 32-character hexadecimal digits by default, it accepts two parameters, the first is the string to be encrypted, the second is a raw_output boolean value, the default is False, and if set to TRUE,MD5 () returns the original 16 Bit binary Format Message digest

2.MD5 () is one-way encryption, there is no reverse decryption algorithm, but can still some common strings through the collection, enumeration, collision and other methods to crack

<?php
$username = ' jellybool ';
$password = ' jellybool.com ';
/* Simply md5 the string to encrypt
/echo MD5 ($username);
echo " 
 

Crypt Encryption:

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

1.crypt () accepts two parameters, the first is a string that needs to be encrypted, the second is a salt value (that is, if it is not provided, the default is generated automatically by PHP); Returns a hashed string or a string less than 13 characters in order to distinguish the salt value.
2.crypt () is one-way encryption, like MD5.

<?php
$password = ' jellybool.com ';
Echo Crypt ($password);
Output: $1$FE0.QR5. $WOhkI 4/5vpo7n7tnxhh5k/
* The eight characters between the second $ and the third $ are generated by PHP, changing once per refresh/
echo " 
 

SHA1 Encryption:

String SHA1 (String $str [, bool $raw _output = false]

1. It's a lot like MD5. SHA1 () returns a hash value of 40 characters by default, as in the property of the parameter, the first is the encrypted string, the second is the Raw_output boolean value, the default is False, and if set to TRUE,SHA1 () returns the original 20 Bit RAW Format Message digest
2.SHA1 () is also a single line encryption, there is no reverse decryption algorithm

<?php
$my _intro= "Jellybool";
Echo SHA1 ($my _intro);
Output: C98885c04c1208fd4d0b1dadd3bd2a9ff4d042ca
echo " 
 

UrlEncode Encryption:

String UrlEncode (String $str)
1. A parameter, passing in the string to be encrypted (usually applied to the encryption of the URL),
2.urlencode for bidirectional encryption, can be encrypted with urldecode (strictly speaking, not real encryption)
3. Returns the string, in addition to-_ in this string. All non-alphanumeric characters are replaced with a percent sign (%) followed by a two-bit hexadecimal number, and the space is encoded as a plus (+).

<?php//urlencode () is usually used for hiding the plaintext data in the URL $my _urlencode= "Jellybool.com?jellybool=true + 4-3%5= \& @!";
  Echo UrlEncode ($my _urlencode);
  Output: jellybool.com%3fjellybool%3dtrue+%2b+4-3%255%3d+%5c%26+%40%21 echo " 

Base64 Encoding Encryption:

String Base64decode (String $encodeddata)
1.base64_encode () accepts a parameter, which is the data to encode (here does not say string, because many times base64 is used to encode pictures)
2.base64encode () is bi-directional encryption and can be decrypted using Base64decode ()

Echo Base64_encode ($my _intro);
echo " 
 

An example of a picture:

<?php
/* An example of the application of a picture
* * *
$filename = "Yun_qi_img/index_video.png";

$data =file_get_contents ($filename);
echo Base64_encode ($data);
/* Then you look at the page source will get a large string of base64 strings, and
then use Base64_decode () restore can get pictures
* *

This article is created by Jellybool, the original

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.