Example
<?php$str = "Hello";echo md5($str);?> Output: 8b1a9953c4611296a827abf8c47804d7
Second, the sha1 () function: Definition and usageSha1 () function calculates the SHA-1 hash of the string. The sha1 () function uses the US Secure Hash Algorithm 1. If the operation succeeds, the calculated SHA-1 hash is returned. If the operation fails, false is returned. Syntaxsha1(string,raw)
Parameters |
Description |
String |
Required. Specifies the string to be calculated. |
Charlist |
Optional. The hexadecimal or binary output format is required:
- True-original 20-character binary format
- False-default. 40-character hexadecimal number
Note: this parameter is added in PHP 5.0. |
|
The second is the CRC32 () function: Definition and usageThe CRC32 () function computes the CRC32 polynomial of a string. This function can be used to verify data integrity. SyntaxCRC32 (string) String is required. Specifies the string to be calculated. DescriptionGenerate the 32-bit Cyclic Redundancy checksum polynomial of the string parameter. This is usually used to check whether the transmitted data is complete. Tips and commentsTip: Because PHP integers are signed, many CRC32 verification codes return negative integers, so you need to use sprintf () or printf () to obtain the string that represents the CRC32 verification code. Example 1In this example, the result of CRC32 () is output without the "% u" format character (note that the result is the same ): <?php$str = crc32("Hello world!");echo 'Without %u: '.$str."<br />";echo 'With %u: ';printf("%u",$str);?> Output: Without %u: 461707669With %u: 461707669 Example 2In this example, we will output the CRC32 () results without the "% u" format character (note that the results are different ): <?php$str = crc32("Hello world.");echo 'Without %u: '.$str."<br />";echo 'With %u: ';printf("%u",$str);?> Output: Without %u: -1959132156With %u: 2335835140 Then the uniqid () function: Definition and usageThe uniqid () function generates a unique ID based on the current time in microseconds. SyntaxUniqid (prefix, more_entropy) Prefix is optional. It is the prefix specified by ID. This parameter is useful if two scripts generate IDs in the same subtle way. More_entropy is optional. Specify more entropy at the end of the returned value. DescriptionIfPrefixIf the parameter is null, the returned string contains 13 characters in length. IfMore_entropyIf the parameter is set to true, it is a string of 23 characters. IfMore_entropyIf the parameter is set to true, an extra entropy is added at the end of the returned value (the program is generated by using the combination of linear and remainder values), which improves the uniqueness of the result. Return ValueReturns a unique identifier in the form of a string. Tips and commentsNote: because the system time is used, the IDS generated through this function are not optimal. To generate an absolutely unique ID, use the MD5 () function (please refer to the string function reference ). Example<?phpecho uniqid();?> The output is similar: 4415297e3af8c Then there is the crypt () function: Definition and usageThe crypt () function returns a string encrypted with DES, blowfish, or MD5. In different operating systems, the behavior of this function is different. Some operating systems support more than one algorithm type. During installation, PHP checks what algorithms are available and used. SyntaxCrypt (STR, salt) STR is required. Specifies the string to be encoded. Salt Optional. It is used to increase the number of characters to be encoded to make the encoding more secure. If the salt parameter is not provided, a random value is generated each time the function is called. Tips and commentsTip: the decryption function does not exist. The crypt () function uses a unidirectional algorithm. ExampleIn this example, We will test different algorithms: <?phpif (CRYPT_STD_DES == 1){echo "Standard DES: ".crypt("hello world")."\n<br />";}else{echo "Standard DES not supported.\n<br />";}if (CRYPT_EXT_DES == 1){echo "Extended DES: ".crypt("hello world")."\n<br />";}else{echo "Extended DES not supported.\n<br />";}if (CRYPT_MD5 == 1){echo "MD5: ".crypt("hello world")."\n<br />";}else{echo "MD5 not supported.\n<br />";}if (CRYPT_BLOWFISH == 1){echo "Blowfish: ".crypt("hello world");}else{echo "Blowfish DES not supported.";}?> The output is similar (depending on the operating system ): Standard DES: $1$r35.Y52.$iyiFuvM.zFGsscpU0aZ4e. Extended DES not supported. MD5: $1$BN1.0I2.$8oBI/4mufxK6Tq89M12mk/ Blowfish DES not supported. DescriptionThe exact algorithm depends on the salt parameter format and length. The following are some constants used with the crypt () function. During installation, PHP sets these constants:
- [Crypt_salt_length]
- [Crypt_std_des]
- [Crypt_ext_des]
- [Crypt_md5]
- [Crypt_blowfish]
|