HMAC Signing Process
HMAC (Hash-based Message Authentication Code) is a symmetric message authentication mechanism that combines a cryptographic hash function with a shared secret key to produce a signature that proves both the integrity and authenticity of a message.
HMAC (Hash-based Message Authentication Code) is a symmetric message authentication mechanism that combines a cryptographic hash function with a shared secret key to produce a signature that proves both the integrity and authenticity of a message.
Unlike asymmetric digital signatures, HMAC uses the same key for both signing and verification. This makes it significantly faster and simpler to implement, but it requires that both parties share the secret key securely in advance. HMAC is widely used for API authentication, webhook signature verification, JWT tokens (HS256 variant), and cookie integrity checks.
The HMAC algorithm works by applying the hash function twice with key-derived pads. Specifically, HMAC(K, m) = H((K ⊕ opad) || H((K ⊕ ipad) || m)) where H is the hash function (commonly SHA-256), K is the secret key, opad is the outer padding (0x5c repeated), and ipad is the inner padding (0x36 repeated). In practice, you never implement this manually — all crypto libraries expose an HMAC function directly.
During signing, the sender runs the message and secret key through HMAC-SHA256 to produce a fixed-length signature (32 bytes for SHA-256). This signature is transmitted alongside the message, typically as a hex string or base64-encoded value in a header like X-Signature or as part of an Authorization header.
On the verification side, the receiver independently computes HMAC of the received message using the same shared secret, then compares their computed HMAC to the received HMAC using a constant-time comparison function. Using a constant-time comparison is critical — a naive string equality check is vulnerable to timing attacks where an attacker can deduce the correct HMAC byte-by-byte by measuring response times.
HMAC does not provide non-repudiation (because both parties have the same key, either could have produced the signature), unlike asymmetric Digital Signature Workflow. For webhook use cases, see API Request Signing.