HMAC-SHA256 Hash Generator

Free online HMAC-SHA256 Hash Generator tool. 100% local processing — your data never leaves your device.

General
Password Hashing / KDF
Specialized
Deprecated
Output

Result will be displayed here...

Input Calculate Hash

Usage Guide

About HMAC-SHA256

HMAC-SHA256 (Hash-based Message Authentication Code with SHA-256) is a keyed-hash message authentication code algorithm that combines the SHA-256 hash function with a key mechanism. Standardized by IETF in RFC 2104, it's widely used for API signing, data integrity verification, and authentication. HMAC-SHA256 not only verifies data integrity but also authenticates the data source, making it a core technology in modern web security.

Industry Standard: HMAC-SHA256 is the de facto standard for API signing, adopted by mainstream platforms like AWS, GitHub, Stripe, and PayPal. It combines the security of SHA-256 with HMAC's key verification mechanism, effectively preventing man-in-the-middle attacks, replay attacks, and data tampering. Recommended for all API communications requiring authentication.

Usage Steps

HMAC-SHA256 requires two inputs: a key and a message, generating a fixed-length authentication code:

1. Input KeyFill in the shared secret key in the key input box; both parties must use the same key
2. Input MessagePaste the data to be signed in the message input box (e.g., API request parameters, file content)
3. Calculate HMACClick the 'Calculate Hash' button to compute locally using WebAssembly
4. Copy ResultClick the 'Copy' button on the right to get the 64-character hexadecimal HMAC value for verification or transmission
Privacy Protection: All calculations are performed locally in your browser, data is never uploaded to servers, completely offline processing.

Algorithm Features

HMAC-SHA256 is based on RFC 2104 standard with the following technical characteristics:

Key VerificationRequires shared key to generate and verify HMAC, ensuring message comes from authorized party
Collision ResistanceInherits SHA-256's security with collision complexity of 2^128, impossible to forge valid signatures
Tamper ResistanceAny minor change in message or key results in completely different HMAC value
Fixed LengthOutput is always 256 bits (64 characters) regardless of input length, convenient for storage and transmission
Double HashingUses two layers of hashing (ipad and opad) to enhance security and resist length extension attacks
Key Security: HMAC's security entirely depends on key confidentiality. Keys should be generated using secure random number generators (at least 256 bits), transmitted and stored through secure channels (like HTTPS, encrypted config files), rotated regularly, and access strictly limited. Never hardcode keys in client code or public repositories.

Use Cases

HMAC-SHA256 is widely used in scenarios requiring authentication and data integrity assurance:

API SigningAWS Signature V4, GitHub Webhooks, Stripe API use HMAC-SHA256 to verify request legitimacy
JWT TokensJSON Web Token (HS256) uses HMAC-SHA256 signing to ensure tokens are not tampered with
Webhook VerificationPlatforms like GitHub, Slack, Stripe use HMAC-SHA256 to verify webhook request sources
Cookie SigningWeb frameworks (like Express, Django) use HMAC-SHA256 to sign cookies, preventing tampering
Key DerivationHKDF (HMAC-based Key Derivation Function) uses HMAC-SHA256 to derive subkeys from master keys
Message QueuesRabbitMQ, Kafka use HMAC-SHA256 to verify message integrity

FAQ

Q: What's the difference between HMAC-SHA256 and SHA-256?

A: SHA-256 is a one-way hash function; anyone can compute the hash of the same input. HMAC-SHA256 requires a key; only those with the key can generate and verify HMAC values. Key difference: SHA-256 only verifies data integrity (whether tampered), HMAC-SHA256 verifies both integrity and source authenticity (whether from authorized party). Use cases: Use SHA-256 for file verification, HMAC-SHA256 for API signing and authentication.

Q: How long should the HMAC-SHA256 key be?

A: RFC 2104 recommends key length at least equal to the hash function's output length. For HMAC-SHA256, recommended key length ≥ 256 bits (32 bytes). Shorter keys: If key is shorter than 256 bits, security decreases but remains valid. Longer keys: If key exceeds 512 bits (SHA-256's block size), it's first hashed to 256 bits, providing no additional security. Best practice: Use 256-bit (32 bytes) random keys, store in Base64 or Hex encoding. Use password generator to generate high-strength keys.

Q: How to use HMAC-SHA256 in API signing?

A: Typical API signing flow: 1) Construct signature string: Concatenate request parameters in agreed format (like HTTP method, URL, timestamp, request body). 2) Calculate HMAC: Compute HMAC-SHA256 of signature string using shared key. 3) Add to request: Add HMAC value to request header (like X-Signature) or query parameters. 4) Server verification: Server calculates HMAC using same method and compares with request value. Examples: AWS Signature V4, GitHub Webhooks (X-Hub-Signature-256), Stripe (Stripe-Signature). Note: Signature string construction order must be strictly consistent, typically parameters sorted alphabetically.

Q: Can HMAC-SHA256 prevent replay attacks?

A: HMAC-SHA256 itself cannot prevent replay attacks. Attackers can intercept legitimate requests (including HMAC signatures) and resend them. Defense methods: 1) Timestamp: Include timestamp in signature string, server rejects expired requests (e.g., requests older than 5 minutes). 2) Nonce (random number): Each request uses unique random number, server records used Nonces, rejects duplicates. 3) Request counter: Client maintains incrementing counter, server rejects requests with decremented counters. Best practice: Combine timestamp and Nonce to prevent replay attacks while avoiding server storage of large Nonce sets. AWS Signature V4 and OAuth 1.0 both adopt this approach.

Q: What's the relationship between HMAC-SHA256 and JWT?

A: JWT (JSON Web Token) supports multiple signing algorithms, with HS256 being HMAC-SHA256. JWT consists of three parts: Header, Payload, Signature. The signature uses HMAC-SHA256 to sign base64(header).base64(payload), ensuring token is not tampered with. Advantages: Symmetric encryption, high performance, suitable for internal systems. Disadvantages: Key must be shared across all services, higher key leakage risk. Alternatives: RS256 (RSA signing) or ES256 (ECDSA signing) use asymmetric encryption, more secure but slightly lower performance.

Q: Which is better: HMAC-SHA256 or HMAC-SHA512?

A: Both are secure; choice depends on specific needs. HMAC-SHA256: 256-bit output (64 characters), better performance, wider compatibility, industry standard (used by AWS, GitHub, Stripe). HMAC-SHA512: 512-bit output (128 characters), theoretically higher security, even better performance on 64-bit systems than HMAC-SHA256, but longer output consuming more bandwidth and storage. Recommendation: For most applications, HMAC-SHA256 is the best choice. If you need higher security (like classified government data, long-term valid signatures) or performance on 64-bit servers, choose HMAC-SHA512.

Use Cases

Recommended: API Signature Verification

HMAC-SHA256 is the industry standard for API signing, adopted by mainstream platforms like AWS, GitHub, Stripe, and PayPal. It ensures API requests come from authorized clients and are not tampered with, being core technology for RESTful API security. Typical flow: client calculates HMAC of request parameters using shared key, server verifies signature before processing request.

Recommended Configuration:
  • ✅ HMAC-SHA256 (industry standard, recommended)
  • ✅ HMAC-SHA512 (higher security)
  • EdDSA (Ed25519) (asymmetric signing, more secure)
  • ❌ Avoid HMAC-MD5 (insecure)
Recommended: Webhook Verification

Platforms like GitHub, Slack, and Stripe use HMAC-SHA256 to verify webhook request authenticity. When sending webhooks, platforms calculate HMAC of request body using shared key and add it to request header (like X-Hub-Signature-256). Receivers calculate HMAC using same method and compare, ensuring request comes from platform not attackers.

Recommended Configuration:
  • ✅ HMAC-SHA256 (webhook standard)
  • ✅ Combine with timestamp to prevent replay attacks
  • ✅ Use HTTPS to transmit keys and data
  • 💡 Rotate webhook keys regularly
Recommended: JWT Token Signing (HS256)

JWT's HS256 algorithm uses HMAC-SHA256 signing to ensure tokens are not tampered with. Suitable for internal systems (like microservice communication), high performance and simple implementation. But key must be shared across all services, higher key leakage risk. For public APIs or high-security scenarios, recommend using RS256 (RSA) or ES256 (ECDSA) asymmetric signing.

Recommended Configuration:
  • ✅ HS256 (internal systems, performance priority)
  • RS256 (public APIs, security priority)
  • ✅ ES256 (modern standard, balance performance and security)
  • ❌ Avoid HS256 for public APIs
Recommended: Key Derivation (HKDF)

HKDF (HMAC-based Key Derivation Function) uses HMAC-SHA256 to derive multiple subkeys from master key for different purposes (like encryption, authentication, signing). HKDF is the standard key derivation scheme for TLS 1.3, also adopted by end-to-end encryption apps like Signal and WhatsApp.

Recommended Configuration:
  • ✅ HKDF-SHA256 (TLS 1.3 standard)
  • ✅ HKDF-SHA512 (higher security)
  • Argon2 (password derivation, brute-force resistant)
  • 💡 Use different info parameters for different purposes
Recommended: Cookie and Session Signing

Web frameworks (like Express, Django, Flask) use HMAC-SHA256 to sign cookies and sessions, preventing client tampering. Signed cookie format is typically value.signature, server trusts cookie content only after verifying signature. This is the foundation of stateless session management, avoiding server-side session storage overhead.

Recommended Configuration:
  • ✅ HMAC-SHA256 (web framework standard)
  • ✅ Use HttpOnly and Secure flags
  • ✅ Set reasonable expiration times
  • 💡 Rotate signing keys regularly
Recommended: Message Queue Integrity Verification

Message queues like RabbitMQ, Kafka, Redis Streams can use HMAC-SHA256 to verify message integrity, ensuring messages are not tampered during transmission. Producers calculate HMAC when sending messages and attach it to message, consumers verify HMAC before processing. This is especially important for critical business scenarios like financial transactions and order processing.

Recommended Configuration:
  • ✅ HMAC-SHA256 (standard choice)
  • ✅ Combine with message ID to prevent replay
  • ✅ Use TLS to encrypt transmission channel
  • 💡 Consider using message queue built-in security mechanisms

Best Practice Recommendations

  • HMAC-SHA256 is the industry standard for API signing and authentication, recommended for all scenarios requiring request source verification.
  • Key security is crucial: use at least 256-bit random keys, transmit via HTTPS or encrypted config files, rotate regularly, strictly limit access.
  • Combine timestamp and Nonce to prevent replay attacks, timestamp window recommended at 5-15 minutes.
  • For public APIs or high-security scenarios, consider using asymmetric signing algorithms (like RS256, ES256) instead of HMAC-SHA256.
  • JWT's HS256 is suitable for internal systems; public APIs should use RS256 or ES256.

Discussion & Feedback

0 comments
Me