PHP built-in encryption function detailed _php tips

Source: Internet
Author: User
Tags base64 crypt hash numeric value printable characters urlencode alphanumeric characters asymmetric encryption

MD5 () encryption algorithm

Mode: One-way encryption

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

$STR: Raw String

$raw _output: If the optional raw_output is set to TRUE, MD5 Digest will return in its original binary format in 16-byte length. Returns a hash value in a 32-bit character hexadecimal number form

MD5 two times encryption: MD5 (MD5 ($string, True)

Crypt () encryption algorithm

Mode: One-way encryption

Syntax: String crypt (String $str [, String $salt]), returns a three-column string based on the standard Unix des algorithm or other available alternative algorithms on the system

$STR: PlainText required for encryption

$salt: Encryption of the interference string, is more secure coding

Note: If the encryption does not add this $salt parameter, will randomly generate a jamming string, otherwise refresh the encryption secret text unchanged

Algorithm constants:

[Crypt_salt_length]

The default encryption length. Use standard DES encryption with a length of 2

[Crypt_std_des]

Hashes based on the standard DES algorithm use the two characters in the "./0-9a-za-z" character as the salt value. Using illegal characters in salt values will cause crypt () to fail.

[Crypt_ext_des]

Extended hashing based on the DES algorithm. A 9-character string that consists of 1 underscores followed by a 4-byte loop and a 4-byte salt value. They are encoded into printable characters, 6 bits per character, and the least effective bit is preferred. 0 to 63 is encoded as "./0-9a-za-z". Using illegal characters in salt values will cause crypt () to fail.

[CRYPT_MD5]

The MD5 hash uses a string salt value that starts with a $1$ of 12 characters.

[Crypt_blowfish]

The Blowfish algorithm uses the following salt value: "$2a$", a two-bit cost parameter, "$" and a 64-bit string that is composed of characters in "./0-9a-za-z". Using a character outside this range in the salt value will cause crypt () to return an empty string. The two-bit cost parameter is the logarithm of the number of cycles to 2, and its range is 04-31, which will cause crypt () to fail.

crypt_sha256

The SHA-256 algorithm hashes with a 16 character string salt value that begins with the $5$. If the salt value string begins with "rounds=<n>$", the numeric value of N will be used to specify the number of times the hash cycle is executed, much like the cost parameter of the Blowfish algorithm. The default number of loops is 5000, the smallest is 1000, and the maximum is 999,999,999. N that is outside this range will be converted to the nearest value.

crypt_sha512

The SHA-512 algorithm hashes with a 16 character string salt value that begins with the $6$. If the salt value string begins with "rounds=<n>$", the numeric value of N will be used to specify the number of times the hash cycle is executed, much like the cost parameter of the Blowfish algorithm. The default number of loops is 5000, the smallest is 1000, and the maximum is 999,999,999. N that is outside this range will be converted to the nearest value.

Cases:

if (CRYPT_MD5) {
  echo "MD5 encryption:". CRYPT (' Something ', ' $1$somethin$ ')

SHA1 () encryption algorithm

Mode: One-way encryption

Syntax: String SHA1 (String $str [, bool $raw _output=false]) computes the SHA1 hash value of a string

$STR: Encrypted string

$raw _output: If the optional raw_output parameter is set to True, the SHA1 summary is returned in the original format of 20 character lengths, otherwise the return value is a hexadecimal digit of 40 string length.

URL Coded encryption technology

Encoded URL string: UrlEncode (String $str)

Decodes the encoded URL string: URLDEOCDE (String $str)

Encoding specification: All non-alphanumeric characters except-_ in this string are replaced with a percent sign (%) followed by a two-bit hexadecimal number, and a space is encoded as a plus (+)

Encode the URL according to RFC1738: Rawurlencode (String $str): Returns the string, encodes the space as%20

Decoding encoded Strings: Rawurldecode (String $str): Returns a string in which the percent semicolon followed by a two-bit hexadecimal sequence bean will be replaced with the literal character

The difference between UrlEncode and Rawurlencode is only a space.

BASE64 Coded encryption technology

To encode data using Base64: Base64_encode (String $data)

Decodes data encoded using MIME base64: Base64_decode (String $data [, $strict =false]); $strict: Returns False if the data entered exceeds the Base64 alphabet.

Base64 encoded pictures can also be placed directly in the tab display:

Information encryption Technology:

1 Single Hash Encryption:

This means that the data of different input lengths is computed and the output of fixed length is obtained, and the hash calculation process is one-way, which can not calculate the output of fixed length and thus output information.

2 Symmetric Hash encryption

Encryption and decryption keys are the same key or can be extrapolated to each other.

3 Asymmetric Hash Encryption

Asymmetric encryption and decryption keys are not the same key, one of which is public, is called a public key, and the other is only known to the owner.

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.