RS256: sign with a private key, verify with a public one
RS256 is the most common asymmetric JWT algorithm. The issuer holds an RSA private key and signs; every verifier holds the matching public key and checks. The signature scheme is RSASSA-PKCS1-v1_5 with SHA-256, identified in the JOSE header as RS256. Because the private key never leaves the issuer, a verifier that is compromised cannot issue tokens for the rest of the system.
The asymmetry is the point. With HS256 every verifier can sign; with RS256 a read-only service can verify and nothing more. That property is what makes public JWKS endpoints possible: a service can publish the public key that corresponds to its private signing key and let the world check its tokens.
The signing and verification steps
The issuer hashes header.payload with SHA-256, wraps the hash in the PKCS#1 v1.5 DigestInfo structure, and applies the RSA private-key operation. The result is a byte string the length of the modulus: 256 bytes for a 2048-bit key, 384 for 3072, 512 for 4096. It is base64url encoded and appended as the third segment. A verifier applies the public-key operation, checks the padding and the DigestInfo prefix, and compares the embedded hash with its own hash of the signing input.
The padding is not optional. PKCS#1 v1.5 signature verification must reject a block whose padding is not exactly the expected form; otherwise the scheme is vulnerable to signature forgery. Well-used libraries do this correctly. The practical lesson for JWT work is to use the library's verify function with the right algorithm name rather than assembling RSA operations by hand.
| Key size | Signature bytes | Typical use | Notes |
|---|---|---|---|
| 2048 | 256 | Current default | Minimum for new systems in most guidance |
| 3072 | 384 | Longer-lived systems | About 1.5× the cost of 2048 |
| 4096 | 512 | High-assurance roots | Slow verification, large tokens |
PEM and JWK are two views of one key
A PEM public key is base64 text between -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----. The body is a DER SubjectPublicKeyInfo structure: an algorithm identifier followed by the RSA modulus and exponent. A JWK represents the same values as JSON: kty is RSA, n is the base64url modulus and e is the base64url exponent, usually AQAB for 65537. Either form can be imported by a verifier; converting between them loses nothing.
A certificate is a third container: it wraps the public key with an identity and a signature. Some libraries accept a certificate where a public key is expected and some do not. If a JWKS entry contains x5c, the first certificate in the chain holds the key. Check what your verifier expects before pasting a certificate into a field labelled public key.
Key size, performance and token size
RSA verification is fast, but signatures are large. A 2048-bit RS256 signature is 256 bytes, or about 342 base64url characters, before any claims. An ID token with a few claims easily reaches 1 KB, and a token with groups can reach several kilobytes. That matters for cookies with a 4 KB limit and for services that put tokens in every request. ES256 produces a 64-byte signature with a comparable security level, which is one reason it is popular for high-volume APIs.
Key generation is slow relative to signing, so issuers generate keys once and rotate them on a schedule. A verifier should cache public keys and refresh on an unknown kid rather than fetching the JWKS on every request. The cache lifetime is a trade-off between seeing a new key quickly and protecting the key endpoint from load.
RS256 versus PS256
PS256 uses RSASSA-PSS with MGF1-SHA256 and a 32-byte salt. PSS has a tighter security proof and is the recommended RSA padding for new protocols. The signature is the same length as RS256 but verification requires the salt length as a parameter; a mismatch between 32 and the maximum possible salt is a common interoperability bug. RS256 remains more widely supported, especially in older libraries and hardware tokens.
Whichever you choose, pin it. A verifier configured for RS256 must reject a token whose header says PS256, HS256 or none, even if the key could technically be used for another scheme. The algorithm is part of the trust decision, not a hint from the token.
Operational notes
Protect the private key with the same care as a database password, and preferably better: keep it in an HSM or a managed key service, restrict who can use it, and log every use. Publish only the public key. When rotating, publish the new public key before signing with it, keep the old one available until tokens signed with it expire, and retire it afterwards. A JWKS with two keys during the overlap is normal and expected.
A public key can be shared with the world. A private key should be usable by as few processes as possible, and never by a verifier.
Sources
- RFC 7518 §3.3 — RSA signatures (RS256, PS256)
- RFC 8017 §8.2 — RSASSA-PKCS1-v1_5
- RFC 7517 — JSON Web Key (JWK)
Questions
Is 2048 bits still enough for RS256?
For the near term, yes: 2048-bit RSA is widely accepted and is the minimum in most current guidance. New systems should prefer 3072 bits or an elliptic-curve algorithm. A 2048-bit key produces a 256-byte signature, which is large for a token header or cookie.
Can I verify with the private key?
You can, but you should not need to. The public key is derived from the private key, and a verifier that holds only the public key cannot mint tokens. Distributing a private key to every verifier recreates the HS256 problem with extra steps.
What is the difference between RS256 and PS256?
Both use RSA and SHA-256. RS256 uses RSASSA-PKCS1-v1_5, a deterministic padding scheme; PS256 uses RSASSA-PSS, which adds a random salt and has a security proof. PS256 is the better choice for new designs where both sides support it, but RS256 remains the most widely implemented.
Paste an RSA public key in PEM or JWK form and verify an RS256 sample token.
Open the verifierWritten against the JOSE specifications (RFC 7515–7519), RFC 7636 and RFC 8037; every example can be reproduced in the verifier linked above.
Back to the guides