: This article mainly introduces the encryption of php Development. if you are interested in the PHP Tutorial, refer to it. 1. use the crypt () function for encryption
The crypt () function can encrypt individual data items. the specific syntax is as follows:
String crypt (string str [, tring salt])
Str is the string to be encrypted, and salt is the interference string used for encryption. if the second parameter is removed, an interference string is randomly generated. The crypt () function supports four algorithms and lengths. The specific table is as follows:
The sample code is as follows:
"; $ CryptStr = crypt ($ str); echo" encrypted str: ". $ cryptStr ."
";?>
The running result is as follows:
First run:
Second run:
Result of the third running:
We can see that the results after each encryption are different. Then how can we determine the encrypted string? at this time, you will find that salt should be used. Haha. The following code demonstrates how:
"; $ CryptStr = crypt ($ str," doc "); echo" encrypted str: ". $ cryptStr ."
";?>
The running result is as follows:
You will find that no matter how many times the encrypted string is run, we can determine the encrypted string.
2. use the md5 () function for encryption
The md5 () function uses the MD5 algorithm. The syntax format is as follows:
String md5 (string str [, bool raw_ouput])
Str is the plaintext to be encrypted. if the raw_output parameter is set to true, a binary ciphertext is returned. the default value is false.
3. use the sha1 () function for encryption.
The syntax format is as follows:
String sha1 (string str [, bool, raw_output])
Str is the plaintext to be encrypted. if raw_output is true, a 20-bit binary number is returned. The default value of raw_output is false.