This article introduces some of the functions of cryptography in PHP, please refer to your friends. The functions that implement encryption in PHP are as follows: 1,md5 () 2,sha1 () 3,crc32 () 4,crypt () 5,uniqid () The 1,MD5 () function defines and uses the MD5 () function to calculate the MD5 hash of a string. The MD5 () function uses RSA data security, including the MD5 message selected passage algorithm. If successful, returns the computed MD5 hash, or False if it fails. Grammar MD5 (STRING,RAW) Parameter description string required. Specifies the string to be computed. Rawraw Optional. Specify hexadecimal or binary output format: TRUE-original 16 character binary format false-default. 32-character Hexadecimal comment: This parameter is added in PHP 5.0. Example:
Output: 8b1a9953c4611296a827abf8c47804d7 2,SHA1 () function: Define and use the SHA1 () function to calculate the SHA-1 hash of the string. The SHA1 () function uses the United States Secure Hash algorithm 1. If successful, returns the computed SHA-1 hash, or False if it fails. Grammar SHA1 (String,raw) Parameter description string required. Specifies the string to be computed. Charlist is optional. Specify hexadecimal or binary output format: TRUE-original 20 character binary format false-default. 40-character hexadecimal number Note: This parameter is added in PHP 5.0. 3,CRC32 () function: Define and use the CRC32 () function to calculate the Crc32 polynomial of a string. This function can be used to verify the integrity of the data. The syntax Crc32 (string) string is required. Specifies the string to be computed. Describes the 32-bit cyclic redundancy check code polynomial that generates a string parameter. This is typically used to check the integrity of the data being transmitted. Hints and notes: Because PHP integers are signed, many CRC32 check codes return negative integers, so you need to use the "%u" format of sprintf () or printf () to get a string that represents an unsigned CRC32 checksum. example, the results of CRC32 () will be output (note the same result) in the case of using and not using the "%u" format character:
"; Echo ' with%u: ';p rintf ("%u ", $str);? >
Output: Without%u:461707669with%u:461707669 Example 2, in this case, will output the result of CRC32 () (note the result is not the same) in the case of using and not using the "%u" format character:
"; Echo ' with%u: ';p rintf ("%u ", $str);? >
Output: Without%u: -1959132156with%u:23358351404,uniqid () function: Define and use the UNIQID () function generates a unique ID based on the current time in microseconds. Syntax uniqid (prefix,more_entropy) prefix optional. Specify a prefix for the ID. This parameter is useful if two scripts generate IDs in the same subtle way. More_entropy is optional. Specifies more entropy at the end of the return value. Description if the prefix parameter is empty, the returned string has 13 string lengths. If the More_entropy parameter is set to True, it is 23 strings long. If the More_entropy parameter is set to True, additional entropy is added at the end of the return value (using a combination line with the remainder generator), which results in better uniqueness. The return value returns a unique identifier as a string. Hints and Comment notes: The ID generated by the function is not optimal due to system time. To generate an absolutely unique ID, use the MD5 () function (find in the string function Reference). Example:
Output similar to: 4415297e3af8c5,crypt () function: Define and use the crypt () function to return strings that are encrypted using DES, Blowfish, or MD5. On different operating systems, this function behaves differently, and some operating systems support more than one type of algorithm. At installation time, PHP checks what algorithms are available and what algorithms are used. Syntax crypt (str,salt) str required. Specifies the string to encode. Salt Optional. Used to increase the number of characters encoded in a string to make the encoding more secure. If the salt parameter is not provided, one is randomly generated each time the function is called. Hint and comment hint: The decryption function is not. The crypt () function uses a one-way algorithm. example, the different algorithms will be tested:
";} Else{echo "Standard DES not supported.\n ";} if (crypt_ext_des = = 1) {echo "Extended DES:". CRYPT ("Hello World"). " \ n ";} Else{echo "Extended DES not supported.\n ";} if (crypt_md5 = = 1) {echo "MD5:". CRYPT ("Hello World"). " \ n ";} Else{echo "MD5 not supported.\n ";} if (crypt_blowfish = = 1) {echo "BLOWFISH:". CRYPT ("Hello World");} Else{echo "Blowfish DES not supported.";}? >
Output similar (dependent on operating system): Standard DES: $1$r35. Y52. $iyiFuvM. zfgsscpu0az4e. Extended DES not supported. MD5: $1$bn1.0i2.$8obi/4mufxk6tq89m12mk/blowfish DES not supported. Note that the exact algorithm relies on the format and length of the salt parameter. The following are some of the constants used with the crypt () function. These constants are set by PHP at the time of installation: [Crypt_salt_length][crypt_std_des][crypt_ext_des][crypt_md5][crypt_blowfish] |