HMAC

A way of combining a secret key with a hash function to produce a tag that shows a message came from someone holding the key and was not changed.

In more detail

HMAC stands for hash-based message authentication code. The sender and receiver share one secret key; the receiver recomputes the tag and accepts the message only if the tags match, so an attacker without the key cannot forge one. Because both sides hold the same key, either could have made any valid tag, so an HMAC cannot prove to a third party who sent a message. Compare tags with a constant-time function so timing does not leak information.

Examples

In the APIs course: The course service signs its tokens with HS256, which is HMAC using SHA-256, and webhook receivers commonly check an HMAC of the body.
hmac.new(KEY, msg, "sha256").hexdigest()
hmac.compare_digest(good, tag)
The course uses HMAC to keep its signing demonstration self-contained; real artefact signing uses public-key signatures so verifiers never hold the signing key.

Related terms

Taught in

References

Certification courses