This article mainly introduces relevant information summarizing several encryption methods in PHP development. Friends in need can refer to
1, using the crypt() function for encryption
crypt() function can perform single encryption. The specific syntax is as follows:
string crypt(string str[,tring salt])
where str is the string to be encrypted, and salt is the interference used in encryption. String, if the second parameter is omitted, an interference string will be randomly generated. The crypt() function supports four algorithms and lengths. The details are as follows:
The sample code is as follows:
<?php $str ="I'm jack!!!"; echo "加密前的str为:".$str."<br>"; $cryptStr =crypt($str); echo "加密后的str为:".$cryptStr."<br>"; ?>
The running results are as follows:
First run:
The second run:
The result of the third run:
You can see that the results after each encryption are different. So how to judge the encrypted string? At this time, you will find that salt comes in handy. Ha ha. Let's demonstrate it through a piece of code:
<?php $str ="I'm jack!!!"; echo "加密前的str为:".$str."<br>"; $cryptStr =crypt($str,"doc"); echo "加密后的str为:".$cryptStr."<br>"; ?>
The running results are as follows:
You will find that no matter how many times you run the encrypted string is unchanged, so that we can judge the encrypted string.
2, use the md5() function for encryption
md5() function uses the MD5 algorithm. The syntax format is as follows:
string md5(string str[,bool raw_ouput])
where str is the plaintext to be encrypted. If the raw_output parameter is set to true, a binary ciphertext will be returned. The default is false.
3, use the sha1() function to encrypt
The syntax format is as follows:
string sha1(string str[,bool,raw_output])
str is required Encrypted plaintext, if raw_output is true, then a 20-bit binary number is returned. The default raw_output is false.
The above is the detailed content of Detailed introduction to several methods of encryption in PHP development (pictures and texts). For more information, please follow other related articles on the PHP Chinese website!