Quick revision
The short answer
With RS256, the issuer signs the token with its RSA private key, and the resource server verifies it with the matching public key, which it downloads from the JWKS endpoint and picks by the kid in the token header. After the signature, it checks the claims exp, nbf, iss and, if configured, aud. HS256 instead uses one shared secret for both signing and verifying, so every service that can verify tokens could also mint them, which is why asymmetric algorithms such as RS256 or ES256 are preferred when many services verify tokens.
What to remember
In this answer, we followed an RS256 token through validation. The issuer signs with its RSA private key, the resource server downloads the public keys from the JWKS, picks one by the kid in the header, verifies the signature, and then checks exp and nbf with clock skew, iss, and aud when configured. HS256 uses one shared secret for both signing and verifying, so every verifier could mint tokens, which is why asymmetric algorithms such as RS256 and ES256 are preferred whenever many services verify tokens.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With RS256, the issuer signs the token with its RSA private key, and the resource server verifies it with the matching public key, which it downloads from the JWKS endpoint and picks by the kid in the token header. After the signature, it checks the claims exp, nbf, iss and, if configured, aud. HS256 instead uses one shared secret for both signing and verifying, so every service that can verify tokens could also mint them, which is why asymmetric algorithms such as RS256 or ES256 are preferred when many services verify tokens.
Why this question is asked
Every Spring resource server validates tokens this way, but the steps are hidden behind one property, issuer-uri. Interviewers ask about it because knowing the steps is what lets us debug key rotation failures, pick the right algorithm, and explain why a shared secret is a poor fit for a large system. In this answer, we will recap asymmetric signing, follow one RS256 token through validation in Spring Security, look at the claim checks, and compare HS256.
1A Quick Recap of Asymmetric Signing
RS256 means RSASSA-PKCS1-v1_5 with SHA-256, a signature scheme with a key pair. The private key stays with the issuer and is the only thing that can produce a valid signature. The public key can be shared with anyone and can only check signatures, never create them.
To sign a JWT, the issuer takes the encoded header and payload joined by a dot, hashes them with SHA-256 and signs the hash with the private key. The result, base64url encoded, is the third part of the token. To verify, the resource server recomputes the hash and uses the public key to check that the signature matches it.
2Step by Step: Validating an RS256 Token
Spring Security's NimbusJwtDecoder does the following for each bearer token. First it parses the header and reads alg and kid. It checks that alg is an algorithm it is configured to accept, RS256 by default; the decision comes from its configuration, not from the token, which blocks tricks such as alg none.
Next it needs the public key. At first use it downloads the JWKS, the JSON Web Key Set, from the issuer's jwks_uri, which Spring found in the OpenID configuration when we set issuer-uri. It caches the set and selects the key whose kid matches the header. If no key matches, it refetches the set once, in case the issuer rotated keys, and rejects the token if the kid is still unknown.
Then it verifies the signature with that key. If even one character of header or payload was changed, the hash differs and verification fails. Only after the signature passes does it look at the claims, because claims from an unverified token mean nothing.
7 messages in order. Play them, or step through them one at a time.
After the first fetch, the key comes from the cache and validation is local.
3The Claim Checks
With a valid signature, Spring runs its token validators. JwtTimestampValidator checks exp and nbf against the current time with a clock skew of 60 seconds by default, so a token that expired 30 seconds ago on a slightly fast clock is still accepted, but one that expired 5 minutes ago is not. JwtIssuerValidator checks that iss equals the configured issuer exactly. The audience is checked only if we configure it, for example with the spring.security.oauth2.resourceserver.jwt.audiences property or a claim validator, so we should configure it: without it, a token meant for another API of the same issuer is accepted.
4How HS256 Differs
HS256 is HMAC with SHA-256. There is no key pair, only one shared secret. The issuer computes an HMAC of header and payload with the secret, and the resource server recomputes the HMAC with the same secret and compares. It is fast and simple, and for a single application that both issues and checks its own tokens it can be fine.
| Aspect | RS256 (or ES256) | HS256 |
|---|---|---|
| Keys | private key signs, public key verifies | one shared secret does both |
| What verifiers hold | public key only, safe to share | the secret itself |
| Can a verifier mint tokens? | no | yes |
| Key distribution | JWKS endpoint, rotation by kid | copy the secret to every service |
| Suits | many services, third parties | one app checking its own tokens |
The catch is in the third row. Every service that can verify an HS256 token holds the secret, and anyone with the secret can create a valid token for any user with any roles. With 30 services, that is 30 places where a leak lets an attacker mint admin tokens, and rotation means updating the secret everywhere at once. With RS256, a compromised resource server leaks only a public key, which was public anyway. So when many services verify tokens, we use asymmetric algorithms: RS256, or ES256, which uses elliptic curve keys with much smaller signatures and faster signing for the same security.
5Follow-up questions
Why does the decoder check the algorithm from its configuration rather than the header?
Because the header is controlled by whoever made the token. Libraries that trusted it were tricked into accepting alg none, or into verifying an HS256 token using the RSA public key as the HMAC secret. Fixing the accepted algorithms in configuration closes both attacks.
What happens if the JWKS endpoint is down?
Tokens signed with cached keys keep validating, because verification is local. Only tokens with a new kid fail until the endpoint is reachable again, which is why short outages of the issuer rarely affect APIs.
When would you choose ES256 over RS256?
When token size or signing speed matters, or the provider recommends it. ES256 signatures are 64 bytes against 256 for RS256 with a 2048-bit key. Both are widely supported; the main thing is that all verifiers are configured to accept the chosen algorithm.
6Conclusion
In this answer, we followed an RS256 token through validation. The issuer signs with its RSA private key, the resource server downloads the public keys from the JWKS, picks one by the kid in the header, verifies the signature, and then checks exp and nbf with clock skew, iss, and aud when configured. HS256 uses one shared secret for both signing and verifying, so every verifier could mint tokens, which is why asymmetric algorithms such as RS256 and ES256 are preferred whenever many services verify tokens.
Open with
With RS256, the issuer signs the encoded header and payload with its RSA private key, and anyone with the public key can verify but not sign. In Spring, when I set issuer-uri, the resource server reads the provider's OpenID configuration to find jwks_uri.
Then, if they want more
For each token, NimbusJwtDecoder reads alg and kid from the header, checks that alg is one it is configured to accept, RS256 by default, fetches the JWKS on first use and caches it, picks the key whose kid matches, and refetches once if the kid is unknown, which covers key rotation.
It verifies the signature, and only then runs the claim validators: exp and nbf with sixty seconds of clock skew by default, iss compared exactly with the configured issuer, and aud if I configure audiences, which I always do so tokens for other APIs are rejected.
HS256 is different: it is an HMAC with one shared secret used for both signing and verifying. That is fine for a single application checking its own tokens, but with many services each one holds the secret, so each one could mint tokens for any user, and rotation means changing the secret everywhere.
So with many verifiers I use asymmetric algorithms, RS256 or ES256, where a leaked verifier only exposes a public key.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- RFC 7519, JSON Web Token
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain how a resource server validates a JWT signed with RS256 using a JWKS endpoint...": https://scrivio-interview-library.netlify.app/spring-boot/jwt/ae5bb4ed27/