hash_hmac
Description
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 = "mydata"; $key = "mykey"; $return = hash_hmac($algo, $data, $key); echo $return;
9640147d1c7879b3871167387e592e1b997a6dda30a976b54f6d6f9285c21d571507d0b5b00fa2aceeb816b975b442c4
2 · binary
<? $algo = "sha384"; $data = "mydata"; $key = "mykey"; $binary = true; $return = hash_hmac($algo, $data, $key, $binary); echo $return . PHP_EOL . bin2hex($return);
�@}xy��g8~Y.�zm�0�v�Omo���W����u�B� 9640147d1c7879b3871167387e592e1b997a6dda30a976b54f6d6f9285c21d571507d0b5b00fa2aceeb816b975b442c4