PHP Tutorial - PHP sha1() Function






Definition

SHA converts a string into a hash value in 40-bit hexadecimal number. Checksums are one-way encryption to check the accuracy of input.

SHA stands for the "Secure Hash Algorithm,".

Syntax

PHP sha1() Function has the following syntax.

string sha1 ( string str [, bool raw_output] )

Parameter

If the optional second parameter is true, the SHA1 checksum is in raw binary format whose length is 20.

Return

PHP sha1() Function returns the SHA1 hash value for a string.

Example


<?PHP
print sha1("hello") . "\n"; 
print sha1("Hello") . "\n"; 
print sha1("hello") . "\n"; 
print sha1("This is from java2s.com"); 
?>

sha1() will always give the same output for a given input.

The code above generates the following result.