Skip to content
Toolcroft

Password & Security

HMAC Generator (SHA-256 / SHA-512)

Generate HMAC signatures online using HMAC-SHA-256, HMAC-SHA-512, HMAC-SHA-384, or HMAC-SHA-1. Enter a message and secret key - all computation happens in your browser.

Text size:

What is HMAC?

HMAC (Hash-based Message Authentication Code) is a cryptographic technique that combines a secret key with a hash function (such as SHA-256) to produce an authentication tag for a message. It is defined in RFC 2104 and used extensively in APIs, JWTs, webhooks, and secure protocols.

What is HMAC used for?

HMAC is used wherever you need to verify that a message both arrived intact (integrity) and was produced by someone who knows the shared secret (authenticity). Common use cases include:

  • Signing API requests (AWS Signature V4, Stripe webhooks, GitHub webhooks)
  • JSON Web Tokens (the HS256 / HS512 algorithms)
  • Secure cookie signing
  • TOTP and HOTP one-time password generation

HMAC-SHA-256 vs HMAC-SHA-512

Both are secure. HMAC-SHA-256 produces a 256-bit (64 hex character) tag and is the most commonly required algorithm. HMAC-SHA-512 produces a 512-bit (128 hex character) tag and is marginally faster on 64-bit processors. HMAC-SHA-1 is cryptographically weak and should only be used when a legacy protocol explicitly requires it.

Key length guidance

For maximum security, an HMAC key should be at least as long as the hash output: 32 bytes (256 bits) for HMAC-SHA-256, and 64 bytes (512 bits) for HMAC-SHA-512. Longer keys beyond these thresholds provide no additional security benefit (they are hashed down to the block size internally). Shorter keys significantly weaken HMAC security and should be avoided.

Common use cases

Use caseDetails
JWT signatures (HS256/HS512)Signs the header+payload; shared secret between issuer and verifier
Webhook verificationGitHub, Stripe, and Shopify include an HMAC in the X-Hub-Signature header so receivers can verify the payload
API request authenticationAWS Signature Version 4 signs requests using HMAC-SHA-256
Signed cookie valuesFrameworks like Django and Express sign session cookies with HMAC to prevent tampering

Timing attack warning

When verifying an HMAC, always use constant-time comparison rather than a simple string equality check (===). A standard string comparison short-circuits at the first mismatched character, leaking timing information an attacker can exploit to forge valid HMACs byte-by-byte. In Node.js, use crypto.timingSafeEqual(expected, actual); most languages provide an equivalent function.

Privacy

All HMAC computation runs in your browser using the native Web Crypto API (crypto.subtle). Neither your message nor your secret key is ever transmitted to any server.