Summary of cryptographic usage of PHP function crypt ()

Source: Internet
Author: User
Tags crypt
In PHP functions, there are a number of cryptographic functions, one can implement data encryption function called crypt ()Function. The crypt () function uses a one-way algorithm that does not have a corresponding decryption function. It returns a string that is encrypted using the DES, Blowfish, or MD5 algorithms. On the surface, the function of crypt () does not seem useful, but the function is widely used to ensure the integrity of the system's passwords. Because a one-way encrypted password, even if it falls into the hands of a third party, is not very useful because it cannot be reverted to plaintext. Let's take a summary of the use of the Crypt () function, hoping to help you with your PHP learning.

Crypt () function related content

1. PHP cryptographic function-crypt () function Encryption usage instance

Before introducing cryptographic functions, let us first introduce the principle of data encryption: that is, the original Ming file or data in accordance with an algorithm for processing, making it an unreadable piece of code, often referred to as "ciphertext", through such a way to achieve the purpose of protecting data from illegal stealing and reading! The main functions that can encrypt data in PHP are: Crypt (), MD5 (), and SHA1 (), as well as the encryption extension mcrpyt and mash. In this article, we first introduce the use of the CRPYT () function for encryption!

2. Using the crypt () function to encrypt-php encryption technology

Crypt () function is one-way encryption, ciphertext can not be reduced to plaintext, the data after each encryption is not the same, how to judge it?

-This is the problem that the salt parameter solves. The crypt () function uses the salt parameter to encrypt the plaintext, and when it is judged, the output information is encrypted again using the same salt parameter, which is compared with the result of two times encryption.

3. Code that uses crypt () to implement user authentication in PHP

The crypt () function is defined as follows. String crypt (String input_string [, string salt])
Where the input_string parameter is a plaintext string that needs to be encrypted, the second optional salt is a bit string that can affect the cryptographic cipher, further eliminating the possibility of being cracked. By default, PHP uses a 2-character des interference string, and if the system uses MD5 (refer to the next section), PHP uses a 12-character interference string. You can find the length of the interfering string that the system will use by executing the following command.
Print "My system salt size is:". Crypt_salt_length;

4. Use crypt () in PHP for user authentication

The crypt () function returns a string that is encrypted with DES, Blowfish, or MD5. On different operating systems, this function behaves differently, and some operating systems support more than one type of algorithm. At installation time, PHP checks what algorithms are available and what algorithms are used. as long as there is a bit of experience with non-Windows platform readers can be quite familiar with crypt (), this function is called one-way encryption function, it can encrypt some plaintext, but not in turn, the password is converted to the original plaintext.

5. Functions of PHP function crypt ()

These encrypted passwords in the PHP function crypt () correspond to the plaintext of Kent, banner, and Parker respectively. Note the first two letters of each password, this is because I used the following code, based on the first two letters of the password to create a disturbance string I will use the Apache password-answer authentication configuration prompts the user to enter a user name and password, a little-known information about PHP is that it can put Apache Password-Answering system the user name and password entered are identified as $php_auth_user and $PHP_AUTH_PW, which will be used in the authentication script for these two variables.

Related questions

1. Question of laravel5.2 openssl_encrypt ()?

2. Md5-php:crypt () function. May I ask if the secret value after encryption is equal to the salt value?

3. How to Implement the PHP crypt () function in Nodejs

"Recommended"

1. "PHP encryption and decryption class library" 10 PHP encryption and decryption class library download

2. PHP Chinese Web free video tutorial: "Php.cn lonely Nine Cheap (4)-php video Tutorial"

Related Article

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.