Compute HMAC message authentication codes using SHA-256, SHA-512, or MD5 with a custom secret key. Verify API signatures and authenticate messages online.
HMAC signature will appear here
The HMAC Generator computes Hash-based Message Authentication Codes using a shared secret key and your choice of underlying hash function — SHA-256 (recommended), SHA-512 (maximum hash strength), SHA-1 (legacy), or MD5 (compatibility only). HMAC simultaneously provides data integrity (the message has not been altered) and authenticity (the sender knows the secret key), making it the standard mechanism for signing API requests, validating webhook payloads (GitHub, Stripe, Twilio), and constructing JWT signatures. Computation runs in the browser via the Web Crypto API, so neither the message nor the secret key is transmitted to any server.
QWhat is the difference between a hash and an HMAC?
A plain cryptographic hash (e.g., SHA-256) produces a fixed-size digest of a message but provides no authentication — anyone can recompute it without knowing a secret. An HMAC mixes a secret key into the hash computation using a defined scheme (HMAC = hash(key ⊕ opad ∥ hash(key ⊕ ipad ∥ message))), so only parties that know the key can produce or verify the MAC. This makes HMAC suitable for message authentication where a hash alone is not.
QWhich HMAC algorithm should I use?
HMAC-SHA-256 is the best choice for most applications. It is mandated by many security standards (RFC 7519 for JWT HS256, AWS Signature V4) and provides 128 bits of security. HMAC-SHA-512 doubles the output size and is appropriate for very high-security contexts. Avoid HMAC-MD5 in new designs — while it has no known HMAC-specific breaks, MD5 is deprecated and may trigger security scanners.
QHow do I verify a GitHub webhook signature?
GitHub sends an `X-Hub-Signature-256` header containing `sha256=<hex_digest>`. In this tool, set the algorithm to HMAC-SHA-256, paste the raw request body as the message, enter your webhook secret as the key, and compare the hex output with the value after the `sha256=` prefix. A match confirms the payload is authentic.
QShould my secret key be a random string or a password?
For security, the HMAC key should be a cryptographically random binary string of at least 32 bytes (256 bits) for HMAC-SHA-256. Human-memorable passwords have low entropy and are vulnerable to brute-force attacks if an attacker intercepts HMAC values. Use a key generator or `crypto.getRandomValues()` to produce a suitable key.
QWhat is constant-time comparison and why does it matter for HMAC verification?
Standard string comparison short-circuits as soon as two bytes differ, which creates a timing side-channel that can reveal partial information about the expected HMAC value through careful timing measurements. Constant-time comparison always processes all bytes regardless of where a mismatch occurs, preventing this attack. The verify mode in this tool uses a constant-time comparison implementation.
QCan HMAC be used to sign JWTs?
Yes. The HS256, HS384, and HS512 JWT signature algorithms are HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512 respectively. The signed data is `base64url(header) + '.' + base64url(payload)` and the secret is the shared symmetric key. Note that HS256 uses a symmetric key (same key to sign and verify), making it unsuitable for scenarios where issuers and verifiers should be different parties — use RS256 or ES256 (asymmetric) in those cases.