jwtk/jjwt · error · WeakKeyException

The specified RSA signing key is not strong enough to be…

Error message

The specified RSA signing key is not strong enough to be used with JWT RSA signature algorithms.  The JWT specification requires RSA keys to be >= 2048 bits long.  The specified RSA key is ${bitLength} bits.  See https://tools.ietf.org/html/rfc7518#section-3.3 for more information.

What it means

Error "The specified RSA signing key is not strong enough to be used with JWT RSA signature algorithms. The JWT specification requires RSA keys to be >= 2048 bits long. The specified RSA key is ${bitLength} bits. See https://tools.ietf.org/html/rfc7518#section-3.3 for more information." thrown in jwtk/jjwt.

Solutions

  1. Generate an RSA key pair with modulus >=2048 bits (4096 for RS512) via Keys.keyPairFor(SignatureAlgorithm.RS256).
  2. Replace 1024-bit legacy RSA keys; re-issue affected tokens after rotating keys.
  3. If a smaller RSA key must be retained for another purpose, do not use it for JWT signing — provision a compliant key.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java:630 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jwtk/jjwt@fb71496164 (2026-09-09). Data as JSON: /api/errors/f9e67ce0bbd08cc8. Report an issue: GitHub.

Appendix: source

Thrown at api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java:630

            RSAKey rsaKey = (RSAKey) key;
            int bitLength = rsaKey.getModulus().bitLength();

            if (bitLength >= 4096) {
                RS512.assertValidSigningKey(key);
                return RS512;
            } else if (bitLength >= 3072) {
                RS384.assertValidSigningKey(key);
                return RS384;
            } else if (bitLength >= RS256.minKeyLength) {
                RS256.assertValidSigningKey(key);
                return RS256;
            }

            String msg = "The specified RSA signing key is not strong enough to be used with JWT RSA signature " +
                    "algorithms.  The JWT specification requires RSA keys to be >= 2048 bits long.  The specified RSA " +
                    "key is " + bitLength + " bits.  See https://tools.ietf.org/html/rfc7518#section-3.3 for more " +
                    "information.";
            throw new WeakKeyException(msg);
        }

        // if we've made it this far in the method, the key is an ECKey due to the instanceof assertions at the
        // top of the method

        ECKey ecKey = (ECKey) key;
        int bitLength = ecKey.getParams().getOrder().bitLength();

        for (SignatureAlgorithm alg : PREFERRED_EC_ALGS) {
            if (bitLength >= alg.minKeyLength) {
                alg.assertValidSigningKey(key);
                return alg;
            }
        }

        String msg = "The specified Elliptic Curve signing key is not strong enough to be used with JWT ECDSA " +
                "signature algorithms.  The JWT specification requires ECDSA keys to be >= 256 bits long.  " +
                "The specified ECDSA key is " + bitLength + " bits.  See " +

View on GitHub (pinned to fb71496164)