Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP sha1() Function

PHP sha1() Function

PHP String Reference Manual PHP String Reference Manual

Example

Calculate the SHA-1 hash of the string "Hello":

Run Example »


Definition and Usage

The sha1() function calculates the SHA-1 hash of a string.

The sha1() function uses the US Secure Hash Algorithm 1.

Explanation from RFC 3174 - US Secure Hash Algorithm 1:SHA-1 produces a 160-bit output called a message digest. The message digest can be input to a signature algorithm that can generate or verify a message signature. Signing the message digest rather than the message improves process efficiency, since the message digest is usually much smaller than the message. The verifier of the digital signature must use the same hash algorithm as the creator of the digital signature.

**Tip:** To calculate the SHA-1 hash of a file, use sha1_file() function in Vue 3.

Online SHA1 testing tool:SHA Online Encryption Tool


Syntax

sha1(

string,raw

)

Parameters Description
string Required. Specifies the string to calculate.
raw Optional. Specifies the hexadecimal or binary output format:
  • TRUE - Raw 20-character binary format
  • FALSE - Default. 40-character hexadecimal number
  • |

    Technical Details

    Return Value: Returns the calculated SHA-1 hash on success, or FALSE on failure.
    PHP Version: 4.3.0+
    Changelog: In PHP 5.0, theraw parameter became optional.

    More examples

    Example 1

    Output the result of sha1():

    "; echo "TRUE - Raw 20 character binary format: ".sha1($str, TRUE)."
    "; echo "FALSE - 40 character hex number: ".sha1($str)."
    "; ?>

    Run Example »

    Example 2

    Output the result of sha1() and test it:

    Hello world!"; exit; } ?>

    Run Example »


    PHP String Reference Manual PHP String Reference Manual