Calculate the SHA-1 hash of the string "Hello":
The sha1() function calculates the SHA-1 hash of a string.
The sha1() function uses the US Secure Hash Algorithm 1.
From RFC 3174 - The US Secure Hash Algorithm 1: "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature."
Tip: To calculate the SHA-1 hash of a file, use the sha1_file() function.
| Parameter | Description |
|---|---|
| string | Required. The string to be calculated |
| raw | Optional. Specify hex or binary output
format:
|
| Return Value: | Returns the calculated SHA-1 hash on success, or FALSE on failure |
|---|---|
| PHP Version: | 4+ |
| Changelog: | The raw parameter became optional in PHP 5.0 |
Print the result of sha1():
Print the result of sha1() and then test it:
Complete PHP String Reference
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.