← All built-ins / hash_hmac()
hash_hmac()
hash_hmac(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $algo | string | "sha256" |
| $data | string | message to sign |
| $key | string | secret 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