Instance
Computes the SHA-1 hash of the text file "Test.txt":
<?php$filename = "Test.txt"; $sha 1file = Sha1_file ($filename); Echo $sha 1file;? >
The above code will output:
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
Definition and usage
The Sha1_file () function computes the SHA-1 hash of the file.
The Sha1_file () function uses the United States Secure Hash algorithm 1.
Explanation from RFC 3174-the US Secure Hash algorithm 1:sha-1 produces a 160-bit output called the digest. The digest of the paper can be entered into a signature algorithm that can generate or verify the message signature. The signature of the digest, rather than the signature of the message, can improve the efficiency of the process, since the size of the digest is usually much smaller than the message. The authenticator of a digital signature must use the same hashing algorithm as the creator of the digital signature.
Returns the computed SHA-1 hash if successful, or FALSE if it fails.
Grammar
Sha1_file (File,raw)
| parameters |
description |
| file |
required. Specify the documents to be calculated. |
| raw |
optional. A Boolean value that specifies the hexadecimal or binary output format:
|
technical details
| return value: |
|
| php version: |
4.3.0+ |
| update log: |
from PHP 5.1, you can use Sha1_file () by encapsulation. For example: Sha1_file ("http://w3cschool.cc/.") |
More examples
Example 1
Store the SHA-1 hash of "test.txt" in the file:
<?php$sha1file = Sha1_file ("test.txt"); File_put_contents ("Sha1file.txt", $sha 1file);? >
Detects if "Test.txt" has been changed (that is, if the SHA-1 hash has been changed):
<?php$sha1file = file_get_contents ("Sha1file.txt"), if (Sha1_file ("test.txt") = = $sha 1file) {echo "The file is OK."} Else{echo "The file has been changed.";}? >
The above code will output:
The file is OK.