Explainer · Guide

What Is HMAC?

What is HMAC?

SHORT ANSWER

HMAC, Hash-based Message Authentication Code, is a construction that combines a cryptographic hash function with a secret key. It produces a fixed-size code that proves the message came from someone who knows the key and that the message was not altered in transit. Webhook signatures, API request signing, and JWT with HS256 all rely on it.

What HMAC stands for

HMAC means Hash-based Message Authentication Code. It is not a hash function or an encryption algorithm. It is a recipe, defined in RFC 2104 in 1997, that turns any hash function such as SHA-256 into a keyed authenticator.

The two inputs

HMAC takes a message and a secret key, and both sender and receiver share the key. Because the key is mixed into the computation, a valid code can only be produced by someone holding the key.

What a valid code proves

Integrity and authenticity. Integrity means the message has not been changed, because any change alters the code. Authenticity means whoever computed the code knows the key, so the message did not come from a random third party.

How it is computed

The message is combined with the key using two passes of the hash, with an inner and an outer padding known as ipad and opad. That double hashing prevents the length-extension tricks that can break a naive keyed hash.

Where HMAC is used

Webhook payload signatures, API request signing, and cookie and token integrity. If a system signs messages to prove they came from it, it almost always uses HMAC or an asymmetric signature.

TRY IT LOCALLY

Try it in your browser with our HMAC Generator. No upload, no server.

Open HMAC Generator →

FAQ

Is HMAC encryption?

No. HMAC is authentication, not encryption. It proves who signed a message and that it was not changed, but it does not hide the content.

Can HMAC be reversed?

No. The code is a hash-based value, so you cannot recover the message or the key from it. Verification recomputes the code and compares it.

What hash does HMAC use?

Any hash you choose. HMAC-SHA-256 is the most common. The strength depends on the underlying hash and on keeping the key secret.

Why not just hash the key and message together?

A naive concatenation such as hash(key + message) is vulnerable to length-extension attacks for some hashes. HMAC's two-pass structure closes that hole.