Summary of PHP encryption algorithm

Source: Internet
Author: User
Tags crypt md5 digest md5 encryption sha1 sha1 encryption urlencode

<?php

#加密算法

Header (' content-type:text/html;charset=utf-8; ');

$password = ' Hugehugehuge ';

$pwd = ' Hugehuge ';

MD5 encryption, one-way encryption algorithm, two parameters, 1 must write, to encrypt the string,

2 The second parameter is the bool value, which is true, and the MD5 Digest is to be returned in the original binary format of 16 bytes in length. Returns a 32-bit string

Echo ' MD5 default call:<br> ';

echo MD5 ($password);

echo "<BR>";

Echo ' MD5 configuration second parameter call:<br> ';

echo MD5 ($password, true);


CRYP, one-way encryption algorithm, two parameters, 1. A parameter to encrypt the plaintext, it also uses only the beginning of the clear text 8 characters

2. Encrypted interference string, the default is two bits, if not written, the system randomly generated two characters, also known as the salt value or the key.

Echo ' <br> ';

Echo '

echo "Crypt encryption algorithm <BR>";

Echo Crypt ($password);

Echo ' <br> ';

Echo Crypt ($password, ' Hu ');

if (crypt_std_des) {//cryptdes standard algorithm

echo ' <br> standard algorithm, only takes two-bit string as interference string ';

Echo ' <br> ';

Echo Crypt ($password, ' This is a test ');

Echo ' <br>pwd: ';

Echo Crypt ($pwd, ' This is a test ');

Echo ' See if two results are the same <br> ';

}

if (CRYPT_MD5) {//MD5 encryption

Echo ' <BR>MD5 encryption algorithm, the second parameter begins with $1$, ends with $12 bits as interference string including $1$ ';

echo "<br>";

Echo Crypt ($password, ' $1$hellohellohello$ ');

echo "<br>pwd:";

Echo Crypt ($pwd, ' $1$hellohellohello$ ');

}


SHA1 encryption algorithm, returns a 40-bit length string, one-way encryption algorithm

Echo '

Echo SHA1 ($password);

echo "<BR>";

Echo ' MD5 configuration second parameter call:<br> ';

Echo SHA1 ($password, true);


URL encryption and decryption

UrlEncode, all non-alphanumeric strings passed in the string except-_.

is replaced with a percent sign (%) followed by a two-bit 16-digit number, and the space is encoded as a plus (+)

Echo '

$url 1= ' This is a URL ';

Echo UrlEncode ($url 1);

Echo ' <br> ';

$url 2= ' www.qdweb.com?username=2+3%4 huge &king # or \1=1 ';

Echo UrlEncode ($url 2);

/*

Common conversions

? Become%3f

= Become%3d

Space becomes +

% into%25

& Into%26

\ become%5c

+ Become%2b

*/

One use of Echo ' <br>urldecode: Merging parameter,<br> ';

if (!empty ($_get)) {

Print_r ($_get);

}

Echo ' <br> ';

$url 3= ' http://www.qdweb.com/jiami.php?username=huge&age=24 ';

Echo ' <a href= '. $url 3. ' " >urldecode merging Parameters </a> ';


$baidu = ' http://www.baidu.com/s?wd=%E6%85%95%E8%AF%BE%E7%BD%91%20immoc&ie=utf-8&tn=baiduhome_pg&f=8 &rsv_bp=1&rsv_spt=1&rsv_sug3=6&rsv_sug4=109&rsv_sug1=3&rsv_n=2&inputt=8408&rsv _sug=1&bs=immoc%20%20%e6%85%95%e8%af%be%e7%bd%91 ';

Echo ' <br> ';

Echo ' Rawurlencode: ';

Encode by RFC1738, convert space to 20%, other ibid.

Echo Rawurlencode ($url 2);

#解码

$url = ' This is a test! ';

$enurl =urlencode ($url);

Echo ' <br>urlencode encoded: '. $enurl;

$deurl =urldecode ($enurl);

Echo ' <br>urlencode decoded: '. $deurl;

#解码

$url = ' This is a test! ';

$enurl =rawurlencode ($url);

Echo ' <br>rawurlencode encoded: '. $enurl;

$deurl =rawurldecode ($enurl);

Echo ' <br>rawurlencode after anti-coding: '. $deurl;

UrlDecode can also decode 20% into a space

$deurl =urldecode ($enurl);

Echo ' <br>urlencode decodes the Rawurlencode encoded string: '. $deurl;


Base64_encode (), encoding the passed-in string using base64

Typically used in mail, to encode binary images

$data = ' Tiger brother is a God!! ‘;

Echo '

$endata =base64_encode ($data);

Echo $endata;

Base64_decode (Data,bool Strict), decoding data encoded with MIME base64

Returns false if the input data exceeds the Base64 alphabet

Echo ' <br>base64_decode after decryption: ';

echo Base64_decode ($endata);









?>


This article is from "Tiger Brother's Blog" blog, please be sure to keep this source http://7613577.blog.51cto.com/7603577/1531691

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.