HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

hash_hmac_file

Description

The hash_hmac_file of Hash for PHP generate a keyed hash value using the HMAC method and the contents of a given file.

Syntax

hash_hmac_file(
    string $algo,
    string $filename,
    string $key,
    bool $binary = false
): string|false

Parameters

algo

Name of selected hashing algorithm.

filename

The filename of the file to hash.

key

Shared secret key used for generating the HMAC variant of the message digest.

binary

When set to true, outputs raw binary data. false outputs lowercase hexits.

Return

Returns a string containing the calculated message digest as lowercase hexits unless binary is set to true in which case the raw binary representation of the message digest is returned. Returns false if the file filename cannot be read.

Examples

1 · algo filename key

<?

$algo = "sha384";
$filename = $_SERVER['DOCUMENT_ROOT'] . "/assets/txt/1.txt";
$key = "mykey";

$return = hash_hmac_file($algo, $filename, $key);

echo $return;
ddb98e935cd504163634899e3b743724a87b2aafe4fe25594748b8fbdc1dadfafbd74cb48b0efc755cb01044277c45e7

2 · binary

<?

$algo = "sha384";
$filename = $_SERVER['DOCUMENT_ROOT'] . "/assets/txt/1.txt";
$key = "mykey";
$binary = true;

$return = hash_hmac_file($algo, $filename, $key, $binary);

echo $return . PHP_EOL
. bin2hex($return);
ݹ��\�64��;t7$�{*��%YGH�������L���u\�D'|E�
ddb98e935cd504163634899e3b743724a87b2aafe4fe25594748b8fbdc1dadfafbd74cb48b0efc755cb01044277c45e7