HMAC Generator

Generate Keyed-Hash Message Authentication Codes (HMAC) for messages client-side using SHA-1, SHA-256, SHA-384, or SHA-512. Verify signatures in real-time. 100% private browser execution.

Loading HMAC Generator workspace...

What is Keyed-Hash Message Authentication Code (HMAC)?

An HMAC (Keyed-Hash Message Authentication Code) is a specific construct for creating a message authentication code using a cryptographic hash function in combination with a secret cryptographic key. Unlike ordinary hash algorithms, HMAC validates both the integrity (verifying data has not changed) and the authenticity (proving the identity of the sender) of a payload.

Standard hash functions are susceptible to length-extension attacks, where an attacker can append data to a signed message and generate a valid signature without knowing the secret key. HMAC prevents this vulnerability by passing the key and message through double-hashing stages using internal and external padding values (ipad and opad).

HMAC vs. Standard Hashing vs. Symmetric Encryption

It is common to confuse these three security mechanisms. Here is how they compare conceptually:

Security ConceptRequires Secret Key?ReversibilityPrimary Security Objective
Standard Hashing (e.g. SHA-256)NoOne-Way (Irreversible)Data Integrity Checks (detect accidental modifications)
HMAC (e.g. HMAC-SHA256)YesOne-Way (Irreversible)Integrity & Authenticity (detect tampered payloads and verify origin)
Encryption (e.g. AES-256)YesTwo-Way (Decryptable)Data Confidentiality (hide secret message contents from unauthorized views)

Choosing an HMAC Algorithm

Depending on your system capabilities and integration specs, you can choose from several hash backings:

  • HMAC-SHA-256: The default choice for modern web architecture. It offers secure 256-bit signatures and is widely supported by languages and cloud providers (AWS, Azure, Stripe).
  • HMAC-SHA-512: Higher security profile, optimized for 64-bit CPU architectures. Highly suitable for data-critical enterprise environments.
  • HMAC-SHA-1: Legacy choice. Although SHA-1 alone is weak to collision vulnerabilities, HMAC-SHA-1 remains secure but should be deprecated in new projects.

Common Use Case: Webhook Verification

When Stripe or GitHub sends webhooks to your server, they sign the request body. They compute an HMAC signature using a secret signing key shared only with you. This signature is placed in a custom header (e.g. X-Hub-Signature-256).

When your server receives the HTTP POST request, it computes the HMAC of the raw request payload using the same secret. If your locally generated signature matches the signature in the HTTP header, you know the request is genuine, protecting your system from counterfeit API calls.

Security Best Practices for HMAC

  • Keep keys confidential: Never commit secret keys to public version control repositories or print them in diagnostic application logs.
  • Use random keys: Generate keys using cryptographically secure random number generators (e.g. at least 32 bytes/256 bits of entropy).
  • Time-constant comparisons: When verifying signatures in your server code, always use time-constant comparison functions (like Python's hmac.compare_digest or Node.js's crypto.timingSafeEqual) to prevent timing side-channel attacks.

Frequently Asked Questions

HMAC stands for Keyed-Hash Message Authentication Code. It is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It is used to simultaneously verify both the data integrity and the authenticity of a message, ensuring it has not been modified in transit and that it indeed originated from a sender possessing the secret key.

A regular hash (like SHA-256) only checks data integrity: if the input changes, the hash changes. However, anyone can compute a hash. An HMAC uses a secret cryptographic key alongside the message. Because only authorized parties share the secret key, attackers cannot generate a valid HMAC signature for modified payloads. This provides authenticity in addition to integrity verification.

No. Encryption is a two-way function used to hide information (confidentiality). It allows ciphertext to be decrypted back to plaintext with a key. HMAC is a one-way signature function used for validation (integrity and authenticity). You cannot decrypt or recover the original message from an HMAC signature.

Yes. ToolZeno operates 100% client-side. When you type your secret key or load message vectors, all cryptographic computations run locally inside your browser sandbox using JavaScript and the Web Cryptography API. No content, keys, or messages are ever transmitted to our network or external servers, guaranteeing complete confidentiality.

HMAC is widely used in API authentication systems, webhooks, and secure message exchanges. For example, GitHub, Stripe, and Slack sign webhook HTTP headers with an HMAC calculated using a shared secret key. Developers verify these headers by computing the HMAC of the received request payload and comparing it with the header signature.