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

hash_hmac

Description

The hash_hmac of Hash for PHP generate a keyed hash value using the HMAC method.

Syntax

hash_hmac(
    string $algo,
    string $data,
    string $key,
    bool $binary = false
): string

Parameters

algo

Name of selected hashing algorithm.

data

Message to be hashed.

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.

Examples

1 · algo data key

<?

$algo = 'sha384';
$data = 'Hello';
$key = 'secret';

$return = hash_hmac($algo, $data, $key);

echo $return;

?>
0a18a877cf68b022767a7c9be11d132141ee63272d3fd3110897d3c2c86940ad9f07c758545983c09342845cf19cb4b8

2 · binary

<?

$algo = 'sha384';
$data = 'Hello';
$key = 'secret';
$binary = true;

$return = hash_hmac($algo, $data, $key, $binary);

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

?>
�w�h�"vz|��!A�c'-?�����i@���XTY���B�\񜴸
0a18a877cf68b022767a7c9be11d132141ee63272d3fd3110897d3c2c86940ad9f07c758545983c09342845cf19cb4b8
HomeMenu