HMAC Generator & Signature Verifier

Calculate and verify Keyed-Hash Message Authentication Codes (HMAC) conforming to RFC 2104. Supports HMAC-SHA256, HMAC-SHA512, HMAC-SHA384, HMAC-SHA1, and HMAC-MD5 with text or hex secret keys, constant-time signature verification, and code snippets. 100% client-side.
Message Payload 0 characters
Secret Key
Calculated HMAC Digest Computed
Hexadecimal Format 256-bit (64 hex characters)
—
Standard Base64
—
URL-Safe Base64 (No padding)
—
Webhook & Signature Verifier Constant-time comparison
Paste an expected signature received from an API or Webhook header (e.g. X-Hub-Signature-256 or Stripe signature) to verify authenticity:
Awaiting signature input...
Ready-to-Use Code Snippets

  

The Cryptographic Foundations of HMAC (RFC 2104)

A Keyed-Hash Message Authentication Code (HMAC) is a cryptographic construction defined in RFC 2104 and NIST FIPS 198-1. It provides a mechanism for verifying both the data integrity and the authenticity of a message using a shared secret key and an underlying cryptographic hash function (such as SHA-256 or SHA-512).

1. Why Simple Concatenation ($H(key \parallel message)$) Fails

A common mistake made by junior developers is attempting to build an authentication code by hashing the key prepended to the message: $\text{MAC} = H(K \parallel M)$.

For hash functions based on the Merkle-Damgård construction (including MD5, SHA-1, SHA-256, and SHA-512), this naive approach is vulnerable to a catastrophic attack known as the Length Extension Attack:

2. The Inner & Outer Padding Formula

To mathematically defeat length extension attacks, RFC 2104 defines a two-pass nested hashing algorithm:

$$\text{HMAC}(K, m) = H\Big((K' \oplus \text{opad}) \parallel H\big((K' \oplus \text{ipad}) \parallel m\big)\Big)$$

Where:

3. Defending Webhooks Against Timing Attacks

When verifying incoming webhook signatures (such as Stripe, GitHub, or Shopify signatures) in your backend application, never use standard string equality (e.g. signature === calculated or signature == expected):

Standard string comparison operators terminate as soon as the first non-matching byte is encountered. An attacker measuring execution latency with microsecond accuracy can determine which characters matched, allowing them to brute-force a valid HMAC byte-by-byte.

Always use a constant-time comparison primitive:

Frequently Asked Questions

Is HMAC reversible or can the secret key be extracted?
No. HMAC is a one-way cryptographic function. Given an HMAC digest and the original message, it is computationally infeasible to recover the secret key, provided the key has sufficient entropy (at least 128 to 256 bits of randomness).
Should I use Hex or Base64 encoding for HMAC signatures?
Hexadecimal is most common in webhook headers (e.g., GitHub X-Hub-Signature-256: sha256=HEX...), while Base64URL is standard in JSON Web Signatures (JWT / JWS).
Are my secret keys sent to your servers?
Never. HMAC computations utilize the browser's hardware-accelerated Web Cryptography API (crypto.subtle.sign). No keys or payloads ever leave your device.
Copied to clipboard!

We use cookies to enhance your experience. Optional cookies only run if you consent. See our Privacy Policy.