Home > Article > Backend Development > Regarding encryption issues in PHP development
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 character to be encrypted String, salt is the interference string used in encryption. 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:
Second run:
Third run The results of each 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 result is as follows:
You will find that the encrypted string remains unchanged no matter how many times it is run, so we can judge 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])
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 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, then a 20-bit binary number is returned. The default raw_output is false.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About PHP encryption and decryption analysis
# #
The above is the detailed content of Regarding encryption issues in PHP development. For more information, please follow other related articles on the PHP Chinese website!