Pcornel
Browse topics
Options
Recent
Favorites
Security · Technical reference

HMAC

Direct answer

HMAC combines a cryptographic hash with a shared secret key to authenticate message integrity and origin among holders of that key without exposing the key itself.

When to use this

Use it when configuring, checking or troubleshooting HMAC in Cryptography.

First 30 seconds

1. HMAC authenticates messages with a shared key.

2. Used for API signatures, webhooks, JWT HS256.

3. Compare in constant time.

4. Keep keys secret and long.

5. Prefer AEAD for encryption + integrity.

Operational verification

message + key → HMAC → verify

Context & applicabilityCommon mistakes · platform/version boundaries
Common mistakes
Common traps

A valid HMAC shows a holder of the shared key produced the tag for those bytes; it does not provide confidentiality, non-repudiation, freshness or identity among key holders.

Suspicious evidence: plain hash used as MAC, one key across contexts, tag truncation without policy, MAC checked after parsing, timing leak, replay accepted or old/new rotation keys confused.

Platform / version applicability
Cryptography, PKI and secrets
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformCryptography, PKI and secrets
Scope / prerequisiteUse it when configuring, checking or troubleshooting HMAC in Cryptography.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

shared MAC key + canonical message/context → HMAC → message/tag → receiver recomputation and constant-time compare → accept/reject/replay control

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • HMAC ≠ unkeyed hash.
  • HMAC ≠ encryption or confidentiality.
  • Valid HMAC ≠ which shared-key holder created the message.
  • Long key ≠ safe key distribution and separation.
Key checks
  • openssl dgst -sha256 -hmac <key> <file> — compute HMAC
  • python3 -c 'import hmac,hashlib;print(hmac.new(b"k",b"m",hashlib.sha256).hexdigest())' — library
  • Constant-time comparison — hmac.compare_digest
ReferenceWhat it is1 section · depth on demand

Using HMAC

openssl dgst -sha256 -hmac "<key>" file
python3 -c "import hmac,hashlib;print(hmac.new(b'key',b'msg',hashlib.sha256).hexdigest())"

Compare HMACs in constant time (hmac.compare_digest) to avoid timing attacks. Used in JWT HS256, webhook signatures (GitHub, Stripe), API request signing (AWS SigV4) and TOTP.

ReferenceImportant terms & boundaries2 sections · depth on demand

What this shows and what it does not

A valid HMAC shows a holder of the shared key produced the tag for those bytes; it does not provide confidentiality, non-repudiation, freshness or identity among key holders.

In depth

HMAC (Hash-based Message Authentication Code) combines a secret key with a hash function to produce a tag that shows a message's integrity and authenticity to anyone who shares the key. Unlike a plain hash, an attacker cannot compute a valid HMAC without the key.

UseExample
Webhook signaturesGitHub X-Hub-Signature-256
API request signingCloud API signatures (AWS SigV4)
TokensJWT with HS256
OTPHOTP/TOTP
ProtocolsIPsec and TLS integrity (legacy suites)
import hmac, hashlib
tag = hmac.new(secret, body, hashlib.sha256).hexdigest()
hmac.compare_digest(tag, received_tag)       # constant-time comparison

Always compare tags in constant time to avoid timing attacks.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docCryptography, PKI and secrets current

Authoritative/upstream documentation reviewed for bounded claims in Cryptography → HMAC. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://csrc.nist.gov/pubs/fips/197/final · confidence 94%
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
keyed hashhash based MACmessage authentication code HMAC
Embedded reference data

Quick lookup tables

Cryptography → HMAC proof map

Fast scope, effective cryptographic state, verification and closure boundaries for Cryptography → HMAC.

BoundaryEstablishDoes not establish
Scope and intentAsset/data/peer, security property, identity/name, protocol and timeDoes not prove algorithm, key, trust or endpoint correctness
Effective cryptographic stateExact version, algorithm/mode/parameters, key/certificate/path and negotiated resultConfiguration or object presence does not prove correct use
Verification outcomePositive, negative, tamper, expiry/revoke and failure tests correlated with evidenceOne success does not prove every peer, client, path or lifecycle stage
ClosureOriginal operation succeeds; old/unsafe state is retired and regression checks passAdministrative workflow completion alone is not closure
Confirmation

Confirm action

Continue?