What is HMAC (Keyed-Hash Message Authentication)?
A cryptographic construction that combines a secret cryptographic key with a hashing function (like SHA-256) to verify both the data integrity and authenticity of a message.
Dual-Pass Secret Padding Construction
Unlike naive concatenation (`hash(key + message)` which is vulnerable to length-extension attacks), HMAC performs two separate nested hashing operations with inner and outer padding bytes (`ipad` and `opad`): `HMAC(K, m) = H((K' ⊕ opad) || H((K' ⊕ ipad) || m))`.
This mathematical design guarantees that an adversary cannot alter a single byte of the payload or forge signatures without possessing the secret cryptographic key.
Key Advantages & Impact
- Immune to length-extension attacks that affect raw SHA-1 and SHA-256 hash concatenation
- Universal standard for webhook verification across Stripe, GitHub, Shopify, and Slack
- Native hardware-accelerated calculation in modern Web Crypto API and backend runtimes
Common Misconceptions vs Reality
Experience This Technology in DocSwift Tools
Frequently Asked Questions
What is HMAC-SHA256?
It is the HMAC construction instantiated using the SHA-256 cryptographic hash function, generating a 256-bit (32-byte) signature.
Can browsers calculate HMAC signatures locally?
Yes! The SubtleCrypto API supports `crypto.subtle.sign('HMAC', key, data)` in native client-side JavaScript.