jwtk/jjwt · error · WeakKeyException

The ${keyType} key's size (ECParameterSpec order) is ${size}

Error message

The ${keyType} key's size (ECParameterSpec order) is ${size} bits which is not secure enough for the ${name} algorithm.  The JWT JWA Specification (RFC 7518, Section 3.4) states that keys used with ${name} MUST have a size >= ${minKeyLength} bits.  Consider using the ${Keys} class's 'keyPairFor(SignatureAlgorithm.${name})' method to create a key pair guaranteed to be secure enough for ${name}.  See https://tools.ietf.org/html/rfc7518#section-3.4 for more information.

What it means

Error "The ${keyType} key's size (ECParameterSpec order) is ${size} bits which is not secure enough for the ${name} algorithm. The JWT JWA Specification (RFC 7518, Section 3.4) states that keys used with ${name} MUST have a size >= ${minKeyLength} bits. Consider using the ${Keys} class's 'keyPairFor(SignatureAlgorithm.${name})' method to create a key pair guaranteed to be secure enough for ${name}. See https://tools.ietf.org/html/rfc7518#section-3.4 for more information." thrown in jwtk/jjwt.

Source

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

            if (isEllipticCurve()) {

                if (!(key instanceof ECKey)) {
                    String msg = familyName + " " + keyType(signing) + " keys must be ECKey instances.";
                    throw new InvalidKeyException(msg);
                }

                ECKey ecKey = (ECKey) key;
                int size = ecKey.getParams().getOrder().bitLength();
                if (size < this.minKeyLength) {
                    String msg = "The " + keyType(signing) + " key's size (ECParameterSpec order) is " + size +
                            " bits which is not secure enough for the " + name() + " algorithm.  The JWT " +
                            "JWA Specification (RFC 7518, Section 3.4) states that keys used with " +
                            name() + " MUST have a size >= " + this.minKeyLength +
                            " bits.  Consider using the " + Keys.class.getName() + " class's " +
                            "'keyPairFor(SignatureAlgorithm." + name() + ")' method to create a key pair guaranteed " +
                            "to be secure enough for " + name() + ".  See " +
                            "https://tools.ietf.org/html/rfc7518#section-3.4 for more information.";
                    throw new WeakKeyException(msg);
                }

            } else { //RSA

                if (!(key instanceof RSAKey)) {
                    String msg = familyName + " " + keyType(signing) + " keys must be RSAKey instances.";
                    throw new InvalidKeyException(msg);
                }

                RSAKey rsaKey = (RSAKey) key;
                int size = rsaKey.getModulus().bitLength();
                if (size < this.minKeyLength) {

                    String section = name().startsWith("P") ? "3.5" : "3.3";

                    String msg = "The " + keyType(signing) + " key's size is " + size + " bits which is not secure " +
                            "enough for the " + name() + " algorithm.  The JWT JWA Specification (RFC 7518, Section " +
                            section + ") states that keys used with " + name() + " MUST have a size >= " +

View on GitHub (pinned to fb71496164)

Solutions

  1. Generate a compliant EC key pair with Keys.keyPairFor(SignatureAlgorithm.ES256) (P-256) / ES384 (P-384) / ES512 (P-521).
  2. Use an EC key whose curve order is at least the algorithm's minKeyLength bits; ES256 requires >=256 bits (e.g. secp256r1), not smaller curves like secp256k1 for ES256 validation rules here.
  3. Select the ES* algorithm that matches the curve you already have (larger curves need the larger ES* variants).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java:428 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/fb16a4048137bf02. Report an issue: GitHub.