Data Encryption in the status of our lives has become increasingly important, especially taking into account the network took place in a large number of transactions and transfer of large amounts of data. If the use of safety measures are interested, also will be interested to learn PHP to provide a range of security features. In this article, we will introduce these features, to provide some basic usage, so that you can for their own application software to add security features.
Prior knowledge
PHP in detail the security features, we need to spend a bit of time to not come into contact with this aspect of the readers some basic knowledge of cryptography, if the basic concepts of cryptography is already very familiar with, you can skip this part of the past .
Cryptography can be described as popular on the encryption / decryption of research and experiments, encryption is easy to understand information will not be converted into easy-to-understand information on the process of moving to decrypt the information is not easy to understand easy-to-understand information is converted to the original process. Do not understand the information is known as password, easy-to-understand information, known as codes.
Data encryption / decryption will require a certain degree of algorithms can be very simple, such as the famous Caesar code, but the current encryption algorithm should be relatively much more complex, some of which make use of the existing methods can not even decipher the.
PHP encryption as long as there is little experience in the use of non-Windows platform may be on the crypt () is quite familiar with the completion of this function is called a one-way encryption function, it can encrypt a number of codes, but can not be converted to the original password the codes. Although the face of it this seems to be a useless function, but it really has been widely used to ensure the integrity of the system password. Because one-way encrypted password once people fall into the hands of third parties, as can not be reduced to express, and therefore does not have any great usefulness. Validate user input in the password, the user input is also used in a one-way algorithm, if the input and stored by the encrypted passwords match, then enter a message must be correct.
crypt () function
PHP also offers the use of its crypt () function to complete the possibility of a one-way encryption. Here I will briefly introduce the function:
string crypt (string input_string [, string salt])
Input_string parameters which need to encrypt the string, the second optional salt is a bit string, it can influence the encrypted code, and further to rule out is called the possibility of attacks is expected to count. By default, PHP uses a two-character string DES interference, if your system using MD5 (I will be introduced at a later MD5 algorithm), it will use a 12-character string interference. By the way, you can order through the implementation of the following system will be found to interfere with the use of the length of string:
print "My system salt size is:". CRYPT_SALT_LENGTH;
System may also support other encryption algorithm. crypt () to support the four algorithms, the following is its support for the algorithm and the corresponding parameters of the length of salt:
Salt length algorithm
CRYPT_STD_DES 2-character (Default)
CRYPT_EXT_DES 9-character
CRYPT_MD5 12-character beginning with $
CRYPT_BLOWFISH 16-character beginning with $