This article mainly introduces the PHP development of several methods to summarize the relevant information, the need for friends can refer to the following
1, using the Crypt () function for encryption
The crypt () function can be individually encrypted with the following syntax:
String crypt (string str[,tring Salt])
Where Str is the string to be encrypted, the salt is the interference string used for encryption, and if the second parameter is omitted, a disturbance string is randomly generated. The crypt () function supports four algorithms and lengths. Specifically, the following table:
The sample code is as follows:
<?php $str = "I m jack!!!"; echo "str before encryption:". $str. " <br> $cryptStr =crypt ($STR); echo "Encrypted str:". $cryptStr. " <br> ";? >
The results of the operation are as follows:
Run for the first time:
Second run:
Results of the third run:
You can see that the results are different after each encryption. So how to judge the encrypted string, this time you will find that salt will come in handy. Ha ha. Here's a code to illustrate the following:
<?php $str = "I m jack!!!"; echo "str before encryption:". $str. " <br> "; $cryptStr =crypt ($str," Doc "); echo" Encrypted str: ". $cryptStr." <br> ";? >
The results of the operation are as follows:
You will find that no matter how many times the encryption string is run, we can judge the encrypted string.
2, using 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, the Raw_output parameter is set to True to return a binary ciphertext, which defaults to false.
3, using 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, Raw_output returns a 20-bit binary number if true. The default raw_output is false.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!