# How to Sign and Verify API Requests With HMAC, RSA, and JWT

> Generate HMAC signatures, create 2048–4096-bit RSA keypairs, sign and verify SHA256withRSA payloads, build SNAP strings, and sign JWTs locally.

URL: https://uttir.com/blog/how-to-sign-and-verify-api-requests-with-hmac-rsa-and-jwt
Published: 2026-10-26
Author: Uttir
Reading time: 3 min
Tags: security, cryptography, api, jwt, rsa, hmac

## Quick answer

API authentication uses symmetric HMACs when both sides share a secret, asymmetric RSA signatures when partners verify with a public key, and JWTs for portable signed claims. Generate keys, build SNAP canonical strings, sign HS256/RS256 tokens, verify RSA signatures, and identify unknown digests directly in your browser.

Debugging signed webhooks, payment gateway callbacks, or JWT auth headers almost always fails for boring reasons: an extra space in the JSON body, a PKCS#1 vs. PKCS#8 PEM mismatch, or an unverified signature algorithm. Pasting production secrets or private keys into random web tools to check those headers is an avoidable security risk.

All seven cryptographic signing and verification utilities on Uttir run locally inside your browser tab via JavaScript and Web Crypto, with zero network transmission.

## 1. Symmetric signing with HMAC

When both the sender and receiver hold the same shared secret—common for webhook signatures (Stripe, GitHub, Slack) and internal service-to-service headers—use an HMAC rather than a plain hash. A plain SHA-256 hash only checks integrity; an HMAC proves possession of the secret key.

The [HMAC Generator](/hmac-generator) computes keyed-hash authentication codes locally across supported SHA algorithms from your message and secret, and lets you copy the resulting MAC or generate a shareable test link when working with dummy values.

## 2. Asymmetric RSA keypairs, signing, and verification

When external partners need to verify requests without holding your signing secret, asymmetric RSA signatures separate the private signing key from the public verification key:

	
- **Generate a test or staging keypair** in [RSA Keygen](/rsa-keygen) (2048-bit standard, 3072-bit strong, or 4096-bit) and download private and public PEM files directly from Web Crypto.
	
- **Sign a canonical string** in [RSA Sign](/rsa-sign) using either a PKCS#1 or PKCS#8 private PEM (PKCS#1 keys are converted automatically) to produce a Base64 `SHA256withRSA` (`X-SIGNATURE`) string.
	
- **Verify a signature** in [RSA Verify](/rsa-verify) using the public PEM, the exact signed message, and either `SHA256withRSA (PKCS#1 v1.5)` or `RSASSA-PSS` padding.

A signature check fails if even a single whitespace byte or line ending differs between the signed string and the verified string.

## 3. Build BI-SNAP canonical strings without whitespace bugs

Open-banking and payment specifications such as BI-SNAP require strict canonicalization before signing with RSA. Any stray space in a JSON payload changes its SHA-256 body hash and triggers an invalid-signature error from the gateway.

The [SNAP String to Sign](/snap-string-to-sign) tool supports both BI-SNAP request modes locally:

	
- **B2B access token** — builds `clientID | timestamp` and signs with your private key.
	
- **Transactional requests** — minifies your JSON request body, computes its lowercase hex SHA-256 digest, builds `METHOD : relativePath : bodyHash : timestamp`, outputs the exact minified body bytes to send over the wire, and signs the full `stringToSign` into `X-SIGNATURE`.

## 4. Sign HS256 and RS256 JWTs for local testing

When testing middleware or reproducing an expired/custom claim locally, the [JWT Sign](/jwt-sign) tool builds and signs JSON Web Tokens in the browser using either a symmetric HMAC secret (`HS256`) or an RSA private PEM key (`RS256`). Pair it with [JWT Decoder](/jwt-decoder) to inspect claims and expiration timestamps side by side.

## 5. Identify unknown digests in logs or headers

If an integration log drops an unfamiliar checksum or signature digest without naming the algorithm, paste it into [Hash Identifier](/hash-identifier). It classifies hex vs. Base64 encoding, lists candidate algorithms matching the digest length, and lets you hash a suspected plaintext input across standard algorithms to confirm an exact match locally.

## Choosing the right signing mechanism

| Use case | Mechanism | Tools |
| --- | --- | --- |
| Webhook or shared-secret API | Symmetric HMAC-SHA256 | HMAC Generator |
| Partner API / non-repudiation | Asymmetric RSA (PKCS#1 v1.5 / PSS) | RSA Keygen, RSA Sign, RSA Verify |
| BI-SNAP payment requests | Canonicalized RSA-SHA256 | SNAP String to Sign |
| Stateless auth bearer tokens | Signed JWT (HS256 / RS256) | JWT Sign |

## Further reading

Primary specifications: [RFC 2104 — HMAC](https://www.rfc-editor.org/rfc/rfc2104), [RFC 7519 — JSON Web Token (JWT)](https://www.rfc-editor.org/rfc/rfc7519), [RFC 8017 — PKCS #1 RSA Cryptography](https://www.rfc-editor.org/rfc/rfc8017), and [MDN — SubtleCrypto Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto).

## Key takeaways

- Symmetric signing with HMAC
- Asymmetric RSA keypairs, signing, and verification
- Build BI-SNAP canonical strings without whitespace bugs
- Sign HS256 and RS256 JWTs for local testing
- Identify unknown digests in logs or headers

## Frequently asked questions

### Why does a valid RSA signature fail verification when my JSON payload looks identical?

Most transactional signing specs hash the exact request body bytes. Extra indentation, trailing newlines, or reordered keys change the SHA-256 body hash—use the exact minified body string generated by [SNAP String to Sign](/snap-string-to-sign).

### When should I choose HS256 vs. RS256 for signing JWTs?

Use HS256 when the same trusted backend both issues and verifies tokens using a shared secret. Use RS256 when external services or clients need to verify tokens with a public key without having permission to mint new tokens.

### Can RSA Sign accept both PKCS#1 and PKCS#8 private keys?

Yes. [RSA Sign](/rsa-sign) detects the PEM header automatically and converts PKCS#1 private keys in your browser before signing via Web Crypto.

## Related tools

- [HMAC Generator](https://uttir.com/hmac-generator) — Compute a Hash-based Message Authentication Code (HMAC) for any message and shared secret. Supports SHA-256, SHA-512, SHA-1, and MD5. All computation runs in your browser.
- [JWT Sign (HS256 / RS256)](https://uttir.com/jwt-sign) — Sign a JSON Web Token with HS256 (HMAC shared secret) or RS256 (RSA private key). Output is a standard compact JWT (header.payload.signature).
- [RSA Key Generator](https://uttir.com/rsa-keygen) — Generate an RSA key pair in your browser. 2048, 3072 or 4096 bits, exported as PEM — nothing is uploaded.
- [RSA Signature Generator (SHA256withRSA)](https://uttir.com/rsa-sign) — Sign a string with your RSA private key and get the Base64 signature. Accepts PKCS#8 and PKCS#1 keys.
- [RSA Signature Verifier](https://uttir.com/rsa-verify) — Check whether a Base64 RSA signature is valid for a message and public key. SHA256withRSA and PSS supported.
- [SNAP / QRIS Request Signer](https://uttir.com/snap-string-to-sign) — Build the stringToSign and X-SIGNATURE for Indonesian payment APIs. Handles the B2B token and transactional forms.
- [Hash Identifier](https://uttir.com/hash-identifier) — Identify which hash algorithm produced a digest by its structure.

---

For the full HTML article, visit https://uttir.com/blog/how-to-sign-and-verify-api-requests-with-hmac-rsa-and-jwt.
This file is the markdown rendering at https://uttir.com/blog/how-to-sign-and-verify-api-requests-with-hmac-rsa-and-jwt.md. See https://uttir.com/llms.txt for a site-wide summary.
