Skip to main content
← SproulTech

How to replace RS256 JWTs (jose, jsonwebtoken)

To replace RS256 JWTs, find every RS256 and PS256 signer and verifier, generate an EdDSA (Ed25519) or ES256 key, publish both public keys in your JWKS with different kid values, sign new tokens with the new key, verify both until old tokens expire, then delete the RSA key and pin the allowed algorithms.

By Nate Sproul, software engineer · Updated December 1, 2026

How do you find every RS256 and PS256 use?

Search code and config, then check what your JWKS endpoint actually publishes. Cupel is our open-source scanner; it reads jose and jsonwebtoken calls and flags RS256 and PS256 string literals.

  • Run npx github:1Aa1k/cupel --check --forbid-rsa from the repo root. It exits 1 when it finds any RSA form, including RS256 and PS256.
  • Open your JWKS endpoint and look at each key's kty. A value of RSA is a key to replace.
  • Also check other services that verify your tokens: a verifier that only accepts RS256 will reject the new tokens.
  • The scanner is line-based pattern matching, so a clean run means no known pattern was found, not proof. How it works and where it misses: How to find every RSA use in a JS/TS codebase.

Which algorithm replaces RS256, EdDSA or ES256?

Use EdDSA with an Ed25519 key if every verifier you control supports it, and ES256 (ECDSA on P-256) if one of them does not. jose supports both. jsonwebtoken lists ES256 but not EdDSA, so a service that signs or verifies with jsonwebtoken needs ES256.

Neither is post-quantum. NIST IR 8547 deprecates elliptic-curve signatures too, so treat this as a move off RSA now and a second move to ML-DSA later. Doing the rollover once, with a key ID on every key, makes the second move the same job.

How do you roll over without breaking logged-in users?

Run both keys side by side. Tokens already issued keep verifying until they expire, and new tokens use the new key.

  • Generate the new key pair and give it its own kid, different from the RSA key.
  • Publish both public keys in the JWKS. Do not remove the RSA key yet.
  • Switch the signer to the new key. New tokens carry the new kid in the header.
  • Verify against the whole key set. A verifier that selects by kid and alg finds the right key for old and new tokens alike.
  • Wait at least as long as your longest token lifetime, refresh tokens included.
  • Remove the RSA public key from the JWKS, delete the private key, and pin the allowed algorithms in every verifier.

How do you do it with jose?

jose takes the algorithm from the key and the protected header. Each line below uses a function documented in the jose repository.

  • Generate: const { publicKey, privateKey } = await generateKeyPair('EdDSA', { extractable: true }). The extractable option is only needed if you must export the private key; public keys are always extractable.
  • Publish: const jwk = { ...(await exportJWK(publicKey)), kid: 'ed-1', alg: 'EdDSA', use: 'sig' } and add it to the keys array of your JWKS.
  • Sign: await new SignJWT({ sub: userId }).setProtectedHeader({ alg: 'EdDSA', kid: 'ed-1' }).setIssuedAt().setExpirationTime('2h').sign(privateKey).
  • Verify both: const JWKS = createLocalJWKSet({ keys: [rsaJwk, edJwk] }), then await jwtVerify(token, JWKS, { algorithms: ['EdDSA', 'RS256'] }) during rollover. jose's docs say the key is selected using the header's alg and kid.
  • For a remote JWKS use createRemoteJWKSet(new URL('https://example.com/.well-known/jwks.json')) in place of the local set.
  • After rollover: await jwtVerify(token, JWKS, { algorithms: ['EdDSA'] }). For ES256, replace 'EdDSA' with 'ES256' in all of the above.

How do you do it with jsonwebtoken?

jsonwebtoken does not support EdDSA. Its README algorithm table lists HS256, HS384, HS512, RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512 and none, and the supported-algorithm list in its sign.js has no EdDSA. If a service uses jsonwebtoken, move it to ES256, or switch that service to jose to get EdDSA.

  • Sign: jwt.sign(payload, ecPrivateKeyPem, { algorithm: 'ES256', keyid: 'ec-1' }). The README's example of the algorithm option is { algorithm: 'RS256' }; ES256 is in the same table.
  • Verify: jwt.verify(token, ecPublicKeyPem, { algorithms: ['ES256'] }). The README describes algorithms as the list of allowed algorithm names, and its example is { algorithms: ['RS256'] }.
  • During rollover, pass { algorithms: ['ES256', 'RS256'] } and, since jwt.verify accepts a function that fetches the key, pick the public key by the token header kid.

Why pin the allowed algorithms after rollover?

A verifier that accepts whatever the token header says can be told to use a weaker algorithm than you intended. Pass an explicit algorithms list on every verify call. jose documents the default as all algorithms applicable to the key, and says unsecured tokens (alg none) are never accepted. After rollover the list should hold one entry, the new algorithm, so a leftover RSA path fails closed.

Then re-run npx github:1Aa1k/cupel --check --forbid-rsa in CI so RS256 cannot return unnoticed.

Where else does RSA hide?

Tokens are one place. TLS certificates, SSH keys and DNSSEC are others, and the RSA exit plan lists how to find each. The wider method of putting every algorithm behind one helper is on the crypto agility case study.

If you want the engineer who wrote this to do the swap, the fix sprint is $2,500 per repo for up to 25 RSA call sites, plus $75 for each site after that. Details on the RSA exit page.

Questions

Can jsonwebtoken sign with EdDSA?
No. The jsonwebtoken README algorithm table and the supported-algorithm list in its sign.js do not include EdDSA. Use ES256 with jsonwebtoken, or use jose if you want EdDSA.
Is EdDSA (Ed25519) post-quantum?
No. It survives a break of RSA factoring but not a large quantum computer, and NIST IR 8547 deprecates it. Treat it as a stopgap before ML-DSA.
How long do I keep the old RSA key in the JWKS?
At least as long as the longest lifetime of any token it signed, refresh tokens included. After that, remove the public key, delete the private key and pin the allowed algorithms.

Send a few lines about where your tokens are signed and verified. The reply comes from the engineer who would do the work.

nate@sproultech.com