A Keyed-Hash Message Authentication Code (HMAC) proves both data integrity (the payload was not altered in transit) and authenticity (the sender holds the shared secret key). Reproducing a provider's signature requires matching three exact parameters: the underlying hash primitive, the raw byte decoding of the secret key, and the exact byte sequence of the signed payload.
Example 1: IETF RFC 2104 / RFC 2202 / RFC 4231 Test Case 2
Whether you enter the 4-byte secret key as UTF-8 text Jefe, raw hexadecimal 4a656665, or Base64 SmVmZQ==, it decodes to the identical key buffer [0x4a, 0x65, 0x66, 0x65]. Signing the 28-byte UTF-8 message what do ya want for nothing? yields:
{
"keyUtf8": "Jefe",
"keyHex": "4a656665",
"keyBase64": "SmVmZQ==",
"message": "what do ya want for nothing?",
"signatures": {
"hmac_md5_hex": "750c783e6ab0b503eaa86e310a5db738",
"hmac_sha1_hex": "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
"hmac_sha256_hex": "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843",
"hmac_sha256_base64": "W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=",
"hmac_sha256_base64url": "W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM",
"hmac_sha384_hex": "af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649",
"hmac_sha512_hex": "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737"
}
}
Example 2: Base64 vs Base64URL and Webhook Canonical Payloads
Standard Base64 (RFC 4648 Section 4) emits +, /, and trailing = padding, whereas URL-safe Base64URL (RFC 4648 Section 5, used in JWS/JWT signatures and signed URLs) substitutes - for +, _ for /, and strips = padding. Signing The quick brown fox jumps over the lazy dog with UTF-8 key key under HMAC-SHA256 illustrates the encoding difference directly:
Key (UTF-8): key
Message (UTF-8): The quick brown fox jumps over the lazy dog
HMAC-SHA256 Hex: f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
HMAC-SHA256 Base64: 97yD9DBThCSxMpjmqm+xQ+9NWaFJRhdZl0edvC0aPNg=
HMAC-SHA256 Base64URL: 97yD9DBThCSxMpjmqm-xQ-9NWaFJRhdZl0edvC0aPNg
When verifying real-world webhook headers, construct the exact pre-signing payload defined by each provider before stripping header prefixes:
GitHub (X-Hub-Signature-256: sha256=<hex>):
Signed input = <raw_http_body>
Stripe (Stripe-Signature: t=1730419200,v1=<hex>):
Signed input = 1730419200.<raw_http_body>
Slack (X-Slack-Signature: v0=<hex>):
Signed input = v0:1730419200:<raw_http_body>
Shopify (X-Shopify-Hmac-Sha256: <base64>):
Signed input = <raw_http_body>