PHP sha1()
Function
Example
Calculate the SHA-1 hash of the string "Hello":
Definition and Usage
The sha1()
function calculates the SHA-1 hash of a string.
The sha1()
function uses the United States Secure Hash Algorithm 1.
Explanation from RFC 3174 - United States Secure Hash Algorithm 1: SHA-1 produces a 160-bit output called a message digest. The message digest can be input into a signature algorithm that generates or verifies message signatures. Signing the message digest rather than the message often improves the efficiency of the process, as the message digest is usually much smaller than the message. The verifier of a digital signature must use the same hash algorithm as the creator of the signature.
Tip: To calculate the SHA-1 hash of a file, use the sha1_file() function.
Syntax
Parameter | Description |
---|---|
string | Required. Specifies the string to be calculated. |
raw | Optional. Specifies hexadecimal or binary output format: TRUE - Raw 20-character binary format<br> FALSE - Default. 40-character hexadecimal number |
Technical Details
Return Value: | Returns the calculated SHA-1 hash if successful, or FALSE if failed. |
---|---|
PHP Version: | 4.3.0+ |
--- | --- |
Changelog: | The raw parameter became optional in PHP 5.0. |
--- | --- |
More Examples
Example 1
Output the result of sha1()
:
Example 2
Output the result of sha1()
and test it: