PHP encryption Technology

Source: Internet
Author: User
Tags crypt md5 digest sha1 sha1 encryption sha1 hash alphanumeric characters
a few days ago learned some knowledge of PHP encryption, now summarize

Several forms of encryption in PHP

MD5 () encryption algorithm

Crypt () encryption algorithm

SHA1 () encryption algorithm

URL Encoding encryption technology

BASE64 Coded encryption technology

MD5 () encryption algorithm

Grammar:

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

$STR: Original string optional (infrequently used)

$raw _output: If the optional raw_output is set to true, then the MD5 digest will be returned in the original binary format of 16 bytes in length. The default is False, which returns the hash value as a 32-bit character 16 binary number.

But only using MD5 encryption algorithm, it is easy to be cracked, such as the Internet has the relevant MD5 decryption site, can be related to the MD5 ciphertext through its website included common MD5 ciphertext query out

Can be strengthened as follows to solve the difficulty

MD5 (MD5 ($STR, True))

Crypt () encryption algorithm

Grammar:

String crypt (String $str [, String $salt]) that returns a hash string based on the standard Unix des algorithm or other available alternative algorithms on the system.

$STR: Confidential plaintext required

$salt: Interference string when encrypting, it is more safe to encode

Attention:

If the $salt parameter is not added to the encryption, a disturbance string is randomly generated, otherwise the encryption text will be refreshed.

SHA1 () encryption algorithm

Grammar:

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

$STR: Encrypted string

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

Returns the SHA1 hash value string

Encrypted ciphertext via SHA1 can also be queried on the website in clear text. SHA1 encryption is not recommended when saving passwords

SHA1 (MD5 ("admin", true))

URL Encoding encryption technology

1.urlencode (String $str): encoded URL string

$STR: The string to encode

Return value: Returns the encoded string

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

2.urldecode (String $str): Decodes the encoded URL string.

3.rawurlencode (String $str): Encode URLs by RFC1738

$STR: The URL to encode

Return value: Return string, encode space as%20

4.rawurldecode (String $str): Decodes an encoded URL string

$STR: the URL to decode

Return value: Returns a string in which the percent percent in this string followed by a two-bit hexadecimal sequence is replaced with the literal character

$STR: the string to decode

Return value: Returns the decoded string

BASE64 Coded encryption technology

1.base64_encode (String $data): Encode data using base64

$data: The data to encode

2.base64_decode (String $data [. bool $strict = false]): Decodes data encoded with MIME base64

$strict: Returns False if the input data exceeds the Base64 alphabet

The above describes the PHP encryption technology, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.