Skip to content
Quantum-safe (classical)jwt-hs256

JWT signed with HS256

JSON Web Tokens authenticated with HMAC-SHA-256 and a shared secret.

Why it's safe

HMAC is symmetric, so it is not affected by Shor's algorithm; with a random secret of at least 256 bits it is quantum-safe. The real risks are classical: weak, short or hard-coded secrets, and verifiers that accept the "none" algorithm or confuse HS256 with RS256 (see RFC 8725). It only suits cases where the issuer and verifier can share a secret.

Used for
MAC
Family
Token MAC (HMAC)
Classical security
128 bits
Against a quantum computer
~128 bits
Standards
RFC 7518 (JWA), RFC 7519 (JWT), RFC 8725 (JWT BCP)
Read the guideMigration playbook

Migration guides

How to adopt JWT signed with HS256. Pick your stack.

JOSE / JWT libraries (e.g. jose) · javascriptJWT/JOSE: what the post-quantum state is, and how to get ready without breaking loginsExperimental

Why

JWTs signed with RS256/PS256 or ES256/EdDSA can be forged once a large quantum computer can recover the issuer's private key from its published JWKS. Tokens are short-lived, so this is not a harvest-now-decrypt-later problem: the deadline is "before such a machine exists", not today. But identity systems are slow to change, so preparation pays off.

State of standards (late 2026):

  • RFC 9964 ("ML-DSA for JOSE and COSE", 2026) registers the JWS algorithms ML-DSA-44, ML-DSA-65 and ML-DSA-87 and a new JWK key type AKP (Algorithm Key Pair).
  • Composite (hybrid) ML-DSA + ECDSA/EdDSA signatures for JOSE/COSE are still an IETF draft (draft-ietf-jose-pq-composite-sigs).
  • Library support is emerging. For example, the jose npm package supports the ML-DSA JWS identifiers since v6.1.0 where the JavaScript runtime's WebCrypto implements ML-DSA. Most identity providers, API gateways and OIDC client libraries do not yet issue or accept ML-DSA tokens.

Steps

  1. Inventory issuers and verifiers: npx -y pqe-cli scan . flags RS*/ES*/HS* usage. List every service that validates your tokens.
  2. Make algorithms configuration, not code. Verifiers should take an allow-list of algorithms and fetch keys from a JWKS by kid. Never accept alg blindly from the token header (RFC 8725).
  3. Practise key rotation now (publish a new kid, sign with it, retire the old one). The PQ migration is a rotation where the new key has a new algorithm.
  4. First-party tokens: if the issuer and verifier are the same organisation and can share a secret, HS256 with a random 256-bit secret is already quantum-safe.
  5. Pilot ML-DSA where both ends are yours: add ML-DSA-65 (or ML-DSA-44 if size matters) to verifier allow-lists, publish an AKP key in the JWKS, then switch signing.
  6. Third-party IdPs (Auth0/Okta/Entra/Cognito/Keycloak...): track their roadmaps; keep your verifiers ready to accept new algorithms.

Before

js
import { SignJWT, jwtVerify, createRemoteJWKSet } from 'jose';

const token = await new SignJWT({ sub: 'user-1' })
  .setProtectedHeader({ alg: 'RS256', kid: 'rsa-2024' })
  .setExpirationTime('15m')
  .sign(rsaPrivateKey);

const JWKS = createRemoteJWKSet(new URL('https://issuer.example/.well-known/jwks.json'));
await jwtVerify(token, JWKS); // accepts whatever alg the key allows

After (agile verifier; ML-DSA where supported)

js
import { SignJWT, jwtVerify, createRemoteJWKSet, generateKeyPair } from 'jose';

// Verifier: explicit allow-list that can grow without a code change
const ALLOWED = (process.env.JWT_ALGS ?? 'RS256,ML-DSA-65').split(',');
const JWKS = createRemoteJWKSet(new URL('https://issuer.example/.well-known/jwks.json'));
const { payload } = await jwtVerify(token, JWKS, { algorithms: ALLOWED, issuer: 'https://issuer.example' });

// Issuer (pilot): requires a jose version and runtime with ML-DSA support (e.g. recent Node 24+)
const { privateKey } = await generateKeyPair('ML-DSA-65');
const pqToken = await new SignJWT({ sub: 'user-1' })
  .setProtectedHeader({ alg: 'ML-DSA-65', kid: 'mldsa-2026' })
  .setExpirationTime('15m')
  .sign(privateKey);

Gotchas

  • Size. An ML-DSA-65 signature is 3,309 bytes, about 4.4 KB once base64url-encoded, against 342 characters for RS256. Tokens in cookies (4 KB browser limit per cookie) or HTTP headers (proxies often cap total headers at 8-16 KB) may break. ML-DSA-44 is smaller (2,420-byte signatures) but still large; consider reference tokens or token exchange at the edge.
  • JWKS size grows too: an ML-DSA-65 public key is 1,952 bytes.
  • Do not invent algorithm names. Use the registered ML-DSA-44/65/87 identifiers from RFC 9964; pre-RFC drafts used other names and key types.
  • Encrypted JWTs (JWE) with RSA-OAEP or ECDH-ES key management are a harvest-now-decrypt-later risk if tokens carry sensitive data and are stored; prefer not putting secrets in tokens, or plan PQ key management once standardised for JOSE.
  • HS256 pitfalls: weak or shared-everywhere secrets, and algorithm-confusion bugs; follow RFC 8725.

Verify

Decode a token header (echo $TOKEN | cut -d. -f1 | base64 -d) to see alg and kid, run your verifier tests with both the classical and the ML-DSA key in the JWKS, and measure the largest token size against your cookie and header limits.