Instance
Computes the SHA-1 hash of the string "Hello":
<?php$str = "Hello"; Echo SHA1 ($STR);? >
Definition and usage
The SHA1 () function computes the SHA-1 hash of the string.
The SHA1 () function uses the United States Secure Hash algorithm 1.
Explanation from RFC 3174-the US Secure Hash algorithm 1:sha-1 produces a 160-bit output called the digest. The digest of the paper can be entered into a signature algorithm that can generate or verify the message signature. The signature of the digest, rather than the signature of the message, can improve the efficiency of the process, since the size of the digest is usually much smaller than the message. The authenticator of a digital signature must use the same hashing algorithm as the creator of the digital signature.
Tip: If you want to calculate the SHA-1 hash of a file, use the Sha1_file () function.
Grammar
SHA1 (String,raw)
Parameter description
string is required. Specifies the string to be computed.
Raw is optional. Specify hexadecimal or binary output formats:
TRUE-Original 20 character binary format
FALSE-Default. 40-character hexadecimal number
Technical details
Return value: Returns the computed SHA-1 hash if successful, or FALSE if it fails.
PHP version: 4.3.0+
Update log: In PHP 5.0, the raw parameter becomes optional.
More examples
Example 1
Results of output SHA1 ():
<?php $str = "Hello"; echo "The string:". $str. " <br> "; echo "true-raw character binary format:". SHA1 ($str, TRUE). " <br> "; echo "FALSE-40 character hex Number:". SHA1 ($STR). " <br> ";?>
Example 2
Output the result of SHA1 () and test it:
<?php$str = "Hello", Echo SHA1 ($STR), if (SHA1 ($str) = = "F7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0") {echo ' <br> Hello world! "; Exit;}? >