Home / Knowledge hub / HMAC
Knowledge hub
HMAC
A hash mixed with a secret key, proving a message is unchanged and from the key holder.
What it means
HMAC stands for keyed-hash message authentication code. It takes a message and a secret key and produces a short tag. Anyone with the same key can recompute the tag and confirm the message was not altered and that the sender knew the key.
It is defined in RFC 2104 and in the US standard FIPS 198-1. It is not encryption: the message stays readable. It gives integrity and authenticity, which means you know the content is intact and came from someone holding the secret.
Why it matters
A message without a tag can be changed in transit or forged outright. With one, a changed amount, a swapped account number or a rewritten permission fails the check. That is why payment providers, cloud platforms and messaging services sign their callbacks.
It is also how many sessions and tokens work. A cookie that carries a user id and an HMAC tag cannot be edited by the user without the key. Skip the tag, check it badly, or let the key leak, and anyone can mint a valid-looking token of their own.
How it shows up
You meet HMAC in signed webhook signatures, API request signing, JWTs signed with HS256, signed cookies and password-reset links. The receiver recomputes the tag over the exact bytes it received, using its own copy of the key, and compares the result with the tag that came with the message.
The mistakes repeat. Comparing tags with a normal equals check, which can leak timing information. Signing a parsed copy rather than the raw body. Using a short or guessable key. Sharing one key across customers. Building the tag as hash(key + message) by hand, which can be extended. Use the library function and a constant-time compare.
Questions people ask
HMAC, answered
Is HMAC the same as a hash?
No. A plain hash such as SHA-256 has no key, so anyone can compute it. HMAC uses a secret key, so only holders of the key can produce a valid tag.
That is the difference between checking a file is intact and checking who made it.
Is HMAC the same as a digital signature?
They solve similar problems differently. HMAC uses one shared secret, so both sides can create tags. A digital signature uses a private key, so only the signer can create them and anyone can verify.
See digital signature.
Does HMAC encrypt the message?
No. The message is still visible. HMAC only proves it was not changed and came from a holder of the key.
If the content is sensitive, encrypt it as well, or send it over HTTPS.
Why should HMAC tags be compared in constant time?
An ordinary comparison stops at the first difference, so response time can reveal how many leading characters matched. With enough measurements an attacker can build a valid tag one piece at a time.
Constant-time comparison functions remove that signal.
Does HMAC stop replay?
No. A valid tag proves a message is genuine, not that it is new. An attacker can send the same signed message again and it still verifies.
Add a timestamp or a single-use identifier inside the signed data, and reject old or repeated ones.
Related
Terms that sit next to this one
Webhook signature
A check that an incoming webhook really came from the service it claims.
Digital signature
A value that proves who produced data and that it has not changed since.
Hashing
A one-way transformation, so a password can be checked but never read back.
Timing attack
Learning a secret by measuring how long your application takes to answer.
Replay attack
Capturing a valid request and sending it again to get the same result twice.
Can a signed message be forged?
We test whether signed values, webhooks and tokens in your app are checked properly, and whether a changed or repeated message is still accepted. Each finding carries the request that proved it. Book a pilot on one app.
Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.