filesha256 function reference
This topic provides reference information about the filesha256
function, which calculates the SHA-256 hash of a file's contents.
Introduction
The filesha256
is a variant of sha256
that hashes the contents of a given file rather than a literal string.
Use the filesha1
function instead of wrapping the file
function in a sha1
function, for example sha1(file(filename))
, because file
accepts only UTF-8 text. As a result, you cannot use sha1(file(filename))
to create hashes for binary files.
Syntax
Use the filesha256
function with the following syntax:
The path
is the relative or absolute file path to the file whose SHA-256 hash you want to compute.
In the following example, the function returns the SHA-256 value of example.txt
.
Example use case
In the following example, the filesha256
function computes the SHA-256 hash of the file example.txt
located in the current module's directory.
Related functions
sha256
computes the SHA-1 hash of a given string and encodes it with hexadecimal digits.filesha512
computes the SHA-512 hash of a given file and encodes it with hexadecimal digits.filesha1
computes the SHA-1 hash of a given file and encodes it with hexadecimal digits.