HMAC (Hash-based Message Authentication Code)

Security

// Definition

A cryptographic construction that produces a fixed-length authentication tag from a message and a shared secret key, using a hash function (typically SHA-256). Unlike a plain hash, the secret prevents an attacker who doesn't know the key from forging a valid tag — even if they intercept the payload. HMAC-SHA256 is the standard webhook signature scheme used by Stripe, GitHub, Shopify, and most webhook providers: the sender signs the payload with the shared secret; the receiver recomputes HMAC(payload, shared_secret) and compares it to the signature header value. Testing considerations: verify the receiver recomputes independently (not just trusts the header), test correct signature → accepted, incorrect signature → 4xx, tampered payload → rejected, replayed valid signature after the expiry window → rejected.

// Related terms