CYBER LIBRARY
Explore the bootcamp
Security essentialsIntermediate

Message authentication codes and HMAC

Use a shared secret to verify message integrity and origin under that key.

3 min readUpdated 12 Oct 20266 connections
Markdown

The idea

A message authentication code provides a tag computed using a secret key and message. HMAC is a construction using a cryptographic hash function. Verification checks the message under the same secret. Because both parties share the key, either can create valid tags; this differs from public-key signatures. Safe use requires key protection, appropriate parameters, and a protocol that addresses freshness when replay matters.

In practice

Two services verify that a webhook payload was authenticated under their shared key before processing it, using the documented signing construction.

A common misunderstanding

A bare hash is not a keyed authentication tag, and a MAC does not by itself prevent replay.

Check your understanding

Why does HMAC not provide the same third-party verification model as a signature?

Think it through: Anyone holding the shared secret can produce the tag.

Agree on the exact authenticated message

A fictional payment provider sends a webhook to a merchant service. Both hold a shared authentication secret. The receiver must verify the tag over the exact message representation defined by the provider's protocol. Reformatting JSON, changing whitespace, or selecting only some fields before verification can make the implementation disagree with that contract.

The protocol should also identify the event and its freshness. A genuine tag proves that the message matches the shared-key authentication calculation; it does not establish that the message has never been processed before. A captured valid webhook might otherwise trigger a duplicate business action. Event identifiers and appropriate replay handling belong in the surrounding design.

Shared keys create shared authority. Either holder can calculate a valid tag, so HMAC is not a way to prove to an unrelated third party which holder authored a disputed message. Use the right mechanism for the required trust model rather than treating every cryptographic authenticator as interchangeable.

Trace verification before processing

For a local exercise, draw receipt of a dummy webhook, authentication verification, freshness checks, and the business update. State what happens if verification fails, if the event was already accepted, and if the event is valid but refers to an unknown order. Each case needs a deliberate outcome.

Keep secrets out of application logs and define a rotation procedure that handles legitimate messages during the transition. Use a maintained implementation and its supported comparison routine rather than creating a custom tag construction. The useful assurance comes from the complete message contract, protected key lifecycle, and controlled processing behavior, not simply from including a hash value beside a request.

Keep exploring

GO TO THE SOURCE

References & further reading

Original explanations, with primary references for deeper study.

NIST: Message Authentication CodesIETF RFC 2104: HMAC
EXPLORE THIS IDEA’S CONNECTIONS

A small part of a bigger picture.

6 notes · 7 connections
100%
Message authentication codes and HMAC · depth 1
Drag to pan · Pinch or use +/− to zoom · Click to preview · Double-click to read
Browse notes as a list (6)
FOLLOW ANOTHER THREADExplore the rest of the library
Start with a concept. Follow its connections.
Detection & responseAbuse Elevation Control MechanismElevation-control abuse bypasses or misuses mechanisms governing privileged execution.Making change happenAcceptance criteriaDefine observable conditions for a deliverable to be accepted.Security essentialsAccess controlUnderstand subjects, resources, permissions, and enforcement through a shared-drive example, including how access changes over time.Detection & responseAccess Token ManipulationAccess token manipulation changes or adopts operating-system security contexts.Risk & resilienceAccount Access RemovalAccount access removal disrupts legitimate users by changing, deleting, or restricting their identities.Evidence & investigationAccount DiscoveryAccount discovery enumerates identities available in a system or environment.Detection & responseAccount ManipulationAccount manipulation changes identity settings to preserve or expand access.Adversarial thinkingAcquire InfrastructureInfrastructure acquisition obtains domains, servers, or other resources used to support operations.Adversarial thinkingActive ScanningActive scanning probes target infrastructure to learn reachable services or weaknesses.Security essentialsAdversary in the middleAn intermediary may observe or alter a communication path.Security essentialsAESA symmetric block cipher whose safe use depends on its mode and implementation.Making change happenAgile deliveryUse short feedback cycles to adapt toward a useful outcome.