Identity and access HMAC 3 min read

What is HMAC?

A payment service sends your server a webhook saying an invoice was paid. How can your server tell the body wasn’t changed on the way?

  1. The sender tags the exact message

    The payment service and your server have a shared secret that only those systems should know. For each webhook, the sender runs the request body and that secret through HMAC, then sends the resulting tag alongside the body.

    The tag is tied to the exact message bytes. Change even one part of the body and the correct tag changes too.

    A payment service sends an invoice event and an HMAC signature to your server. Your server uses its shared secret to verify the signature before trusting the event.

    The signature travels with the body; the shared secret does not.

    In short The sender adds a keyed checksum; the receiver checks it with the same secret.

  2. The receiver checks before acting

    Your server calculates its own HMAC from the received body and the shared secret. If the result matches the supplied tag, the body is intact and came from a party that knows that secret.

    Compare tags with a constant-time comparison and follow the provider’s signing instructions, including how it defines the exact bytes to sign.

    In short Only accept the webhook after its tag verifies.

  3. A valid tag can still be replayed

    An attacker who copies a valid request and its tag can resend both. The HMAC still matches because the message hasn’t changed.

    If repeated delivery could trigger duplicate work, include a signed timestamp or unique event ID and reject stale or already-processed requests.

    In short Integrity checks don’t make a request fresh; handle replay separately.

What HMAC doesn’t guarantee

HMAC doesn’t encrypt the body, so use HTTPS to protect it in transit. It also doesn’t prove which of the two key holders created the tag, or prove a human’s identity.

If the shared secret leaks, an attacker can create valid tags. Store it as a secret, limit who can read it, and rotate it if exposed.

Keep this

HMAC checks a message with a shared secret; it doesn’t hide the message.

Use HMAC when two services share a secret and need to detect message changes. Keep the secret private, sign the exact bytes being sent, and add a timestamp or nonce if replay matters.
Input
The sender computes a tag from the exact message and a shared secret.
Check
The receiver recomputes and safely compares the tag.
Protects
A changed message fails verification, assuming the key stays secret.
Doesn’t
Encrypt the content, identify a human, or prevent replay by itself.

Questions worth carrying

Does HMAC encrypt the webhook body?

No. A tag is a separate integrity check. HTTPS protects the request in transit; HMAC lets the receiver verify the body and shared-secret knowledge at the application layer.

Can the receiver prove which service made the tag?

No. Both parties hold the same key and can compute valid tags, so HMAC does not provide non-repudiation or distinguish the sender from the receiver.

Sources

Last reviewed 20 November 2026.

Next byte · Credentials and request integrity What is an API key?