What verifying a signature proves
A signed JWT carries a signature over its header and payload. Checking that signature with the right key proves two things: the token was created by someone who holds the signing key, and nobody changed a single byte of the header or payload since.
It proves nothing else. A token with a valid signature can still be expired, meant for another API, or issued by a realm you do not trust. Signature first, then claims: that is the order every resource server should follow.
How signature verification works
The verifier rebuilds the signing input, which is the first two parts of the token joined by a dot, exactly as received. It decodes the third part from Base64url into the signature bytes. Then it runs the algorithm named in the header with the key.
| Family | Key to verify with | How it checks |
|---|---|---|
| HS256/384/512 | The same shared secret | Computes the HMAC and compares |
| RS256/384/512 | RSA public key | RSASSA-PKCS1-v1_5 verify |
| PS256/384/512 | RSA public key | RSASSA-PSS verify, salt length equal to the hash size |
| ES256/384/512 | EC public key on P-256, P-384, P-521 | ECDSA verify of the raw r and s values |
| EdDSA | Ed25519 public key | Ed25519 verify |
With asymmetric algorithms, only the private key can sign but anyone with the public key can verify. That is why identity providers publish their public keys and keep the private ones.
A detail about ECDSA
JWS stores ECDSA signatures as the two numbers r and s back to back, each padded to the curve size (RFC 7518, section 3.4). Some libraries produce DER-encoded signatures instead. A DER signature pasted into a JWT fails verification even when the key is right.
What this verifier accepts
- A shared secret, written as text, Base64, Base64url or hex.
- A PEM public key:
BEGIN PUBLIC KEYorBEGIN RSA PUBLIC KEY. - A PEM certificate, from which it takes the public key.
- A PEM private key, from which it uses only the public half.
- A single JWK, or a whole JWKS such as a realm’s certs endpoint. With a set, it picks keys by
kid, type, curve,alganduse.
Tokens that say alg: none are refused before any key is touched. All checks run with your browser’s Web Crypto. Nothing is sent to us.
How to verify a token
- Paste the token. The header badges show its
algandkid. - Paste the key material. For a Keycloak realm, open
https://<host>/realms/<realm>/protocol/openid-connect/certsin a browser and copy the whole JSON. - Leave the key type on Detect, or choose it if detection guesses wrong.
- For a shared secret, choose the format it is written in.
- Read the result, then check the claims with the claims validator.
Verifying Keycloak tokens
Each Keycloak realm signs tokens with its active signing key, RS256 by default. The realm’s public keys are listed at the certs endpoint as a JWKS, and the realm’s discovery document at /realms/<realm>/.well-known/openid-configuration points to it as jwks_uri.
The kid in a token’s header matches the kid of one key in that set. You can see the same key ids in the admin console under Realm settings, Keys.
Other signature algorithms
A realm can sign with other algorithms. Add a key provider for them under Realm settings, Keys, Providers (for example an ECDSA provider for ES256), then choose the algorithm for the realm under Realm settings, Tokens, or per client in the client’s advanced settings. The certs endpoint then lists the new key too.
Refresh tokens
Keycloak signs refresh tokens with a realm HMAC key it never publishes. You cannot verify them here or in your own code, and you do not need to: only Keycloak reads them.
Use cases
Debugging “invalid signature” errors
When your API rejects tokens, verify one here against the realm’s certs JSON. If it passes here, your API is using the wrong keys, a stale cache, or the wrong algorithm. If it fails here too, the token came from somewhere else.
Checking a key rotation
After adding a new key in Keycloak, verify a fresh token against the certs endpoint. Then verify an older token. Both should pass while the old key is still listed.
Testing your own HMAC setup
Paste a test token and the test secret to confirm both sides agree on the secret format. Text and Base64 versions of the “same” secret are different bytes.
Common reasons verification fails
| Symptom | Likely cause |
|---|---|
| No key in the set fits | The token’s kid is not in the set: another realm, another server, or a removed key |
Invalid signature with the right kid | The token was changed, or truncated when copied |
| Needs a RSA key, but this key is EC | The key type does not match the token’s alg |
| Works with text secret, fails with Base64 | The secret format setting does not match how the secret is stored |
| Ed25519 key could not be loaded | An older browser without Ed25519 support in Web Crypto |
A token copied from a terminal or a chat often picks up a line break or loses its last characters. If a genuine token fails, copy it again from the source.
Verifying in code
In production, a library does this on every request. The pattern is the same everywhere: point it at the issuer’s key set, pin the algorithm, and set the issuer and audience.
// Node.js with the jose library
const jwks = createRemoteJWKSet(new URL(
'https://auth.example.com/realms/acme/protocol/openid-connect/certs'));
const { payload } = await jwtVerify(token, jwks, {
issuer: 'https://auth.example.com/realms/acme',
audience: 'orders-api',
algorithms: ['RS256'],
});Use this tool to check single tokens by hand when the library’s error message is not enough.
If a token verifies here but not in your service, compare the service’s configured algorithm list and key source with what you pasted. The difference is almost always there.
Security notes
Two classic attacks target verifiers, not tokens. In the first, an attacker sends alg: none and hopes the verifier skips the check. In the second, an attacker signs with HS256 using the issuer’s public RSA key as the HMAC secret, hoping the verifier lets the token pick the algorithm.
Both fail when the verifier decides the algorithm from its own configuration and checks that the key type fits. This tool does both: it refuses none, and it refuses to use an RSA or EC key with an HMAC algorithm.
A public key or certificate is safe to paste. A shared secret is not public: use a test secret here.
Best practices for verifiers
- Fetch keys from the issuer’s
jwks_uriover HTTPS, cache them, and refresh the cache when a token arrives with an unknownkid. - Allow only the algorithms you expect, such as RS256.
- Never use a key named by the token itself through
jku,x5uor an embeddedjwk. - After the signature, check
exp,nbf,issandaudevery time. - Use a well-maintained library instead of writing the cryptography yourself.