← All built-ins / hash_hmac()

hash_hmac()

hash_hmac(...$args): mixed

Parameters

NameTypeDescription
$algostring"sha256"
$datastringmessage to sign
$keystringsecret key

Return value

HMAC digest as hex — proves the message came from someone holding $key.

Example

$sig = hash_hmac("sha256", "order:42", "secret-key");
echo strlen($sig) == 64 ? "signed" : "bad";
echo hash_hmac("sha256", "order:42", "secret-key") == $sig ? " matches" : " nope";
signed matches

See also

sha256()hash_equals()