Skip to content
Toolcroft

HMAC Generator (SHA-256 / SHA-512)

Password & Security

Generate and verify HMAC-SHA-1/256/384/512 signatures in your browser using UTF-8 or Hex keys and Hex or Base64 output. All computation stays local.

Text size:

Verification runs locally with Web Crypto. Verify production webhooks on your server.

How to use this tool

  1. Enter your message in the Message field.
  2. Enter your secret key.
  3. Select the algorithm (HMAC-SHA-256 recommended).
  4. Choose the output encoding - hex or base64.
  5. Optionally paste an expected signature to check whether it matches this message and key.
  6. Copy the generated HMAC with the copy button.

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.

Verify an expected signature

Paste a known signature in Hex, Base64, or Base64url into the optional verification field. The tool accepts common sha256= and Stripe v1= prefixes, then asks Web Crypto to verify the decoded signature bytes against the current message, key, and algorithm. A match means those inputs produce the supplied tag. HMAC covers the exact message bytes, so changed spaces, line endings, or JSON formatting produce a different signature; an empty message is also a valid input to sign.

Use this browser check for local debugging with test secrets. Verify production webhook requests on your server against the raw request body before processing them, using the provider's documented algorithm and key format. A local match does not establish that a request is safe to accept.

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.

Frequently asked questions

What is an HMAC?

HMAC (Hash-based Message Authentication Code) combines a cryptographic hash function with a secret key to produce a signature. It proves both that a message has not been tampered with (integrity) and that the sender knows the secret key (authenticity).

Which algorithm should I use?

HMAC-SHA-256 is the most widely used choice and is secure for the vast majority of applications. HMAC-SHA-512 offers a larger output (512 bits) and may be slightly faster on 64-bit systems. HMAC-SHA-1 is considered cryptographically weak and should only be used when required by a legacy protocol.

What output encoding should I choose?

Hex produces a lowercase hexadecimal string (e.g., "a94a8fe5..."). Base64 produces a shorter string using letters, digits, + and / (e.g., "qUqP5cyxm6..."). Both represent the same bytes - choose whichever format your API or protocol expects.

Can I enter the key as hex bytes?

Yes. Switch the key encoding to "Hex" and paste a hex-encoded key (e.g., "0b0b0b0b..."). This is useful when testing against published test vectors or working with binary keys.

How do I verify an HMAC?

Paste the expected Hex, Base64, or Base64url signature into the optional verification field. Common sha256=, sha512=, and Stripe v1= prefixes are accepted. The selected algorithm and key encoding must match the system that created the signature. This local check is for debugging and does not replace server-side verification of production webhooks.

Does my secret key leave my browser?

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

Browse all password & security