HMAC
Abbreviation: HMAC
Pronunciation: AYCH-mak
Also known as: Hash-Based Message Authentication Code, Hash-Based Message Authentication Code (HMAC), HMAC
Definition
HMAC (Hash-Based Message Authentication Code) is a cryptographic method that combines a secret key with a hash function to prove that a message has not changed and came from someone holding the same key. APIs and webhook receivers use HMAC to verify signed requests. Its protection depends on signing the exact same bytes, safeguarding the shared secret, rejecting replays, and comparing authentication tags in constant time.
Overview
Meaning and scope
HMAC (Hash-Based Message Authentication Code) is a cryptographic method that combines a secret key with a hash function to prove that a message has not changed and came from someone holding the same key. APIs and webhook receivers use HMAC to verify signed requests. Its protection depends on signing the exact same bytes, safeguarding the shared secret, rejecting replays, and comparing authentication tags in constant time.
Mechanism and operation
HMAC produces a fixed-length authentication tag from three inputs: a message, a shared secret key, and a cryptographic hash function. It processes the key and message through a standardized inner-and-outer hashing construction. A verifier with the same secret repeats that calculation and compares the expected tag with the received tag. Successful verification requires both sides to sign exactly the same bytes. An API therefore needs a canonical representation of the HTTP method, path, timestamp, body, and any other covered fields. This is why API authentication specifications must define the signing payload precisely. Payment platforms commonly use a webhook signature based on HMAC.
Practical payment example
A webhook sender signs the exact request body with a shared secret. The receiver recomputes the HMAC and compares it safely before processing the notification.
Operational checks
The sender signs the webhook payload, and the receiver calculates the tag with its stored secret before processing the event. The receiver should also validate a timestamp or nonce to prevent a valid signed message from being reused in a replay attack. Tag comparison must run in constant time so an attacker cannot infer the expected value from timing differences.
Distinctions and limits
A match provides message integrity and shared-secret authenticity; it does not encrypt the message. Differences in whitespace, character encoding, JSON serialization, or field order can produce different tags even when the data appears equivalent.
Related reading
Related definitions: API authentication, webhook signature.
Example
A webhook sender signs the exact request body with a shared secret. The receiver recomputes the HMAC and compares it safely before processing the notification.
Comparison
A match provides message integrity and shared-secret authenticity; it does not encrypt the message. Differences in whitespace, character encoding, JSON serialization, or field order can produce different tags even when the data appears equivalent.
Key Takeaway
HMAC verifies message integrity and shared-secret authenticity only when both sides sign identical bytes, protect the key, block replays, and compare complete tags safely.
Sources
- RFC 2104: HMAC—Keyed-Hashing for Message Authentication — RFC Editor / IETF (2026-08-02)
- FIPS 198-1: The Keyed-Hash Message Authentication Code (HMAC) — NIST (2026-08-02)
- NIST Documentation: Cryptographic Standards And Guidelines — NIST (2026-07-30)