HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP String Reference : 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."
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.3.0+ |
Print the result of sha1():
<?php
$str = "Hello";
echo "The string: ".$str."<br>";
echo "TRUE - Raw 20 character binary format: ".sha1($str, TRUE)."<br>";
echo "FALSE - 40 character hex number: ".sha1($str)."<br>";
?>
Print the result of sha1() and then test it:
<?php
$str = "Hello";
echo sha1($str);
if (sha1($str) == "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0")
{
echo "<br>Hello world!";
exit;
}
?>
❮ PHP String Reference