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 = 'secret';

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

echo $return;

?>
7e1e620ca0068fd1fce00c1ad3f5c6dbb12874dd2fb9c26502d09d0d804f2c0ba1d921b9458416cba480417571001e18

2 · binary

<?

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

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

echo $return . PHP_EOL . bin2hex($return);

?>
~b������۱(t�/��eН
�O,��!�E�ˤ�Auq
7e1e620ca0068fd1fce00c1ad3f5c6dbb12874dd2fb9c26502d09d0d804f2c0ba1d921b9458416cba480417571001e18
HomeMenu