{"record":{"id":"96d71c221c13ec0f","repo":"jwtk/jjwt","slug":"familyname-keytype-keys-must-be-eckey-instan","errorCode":null,"errorMessage":"${familyName} ${keyType} keys must be ECKey instances.","messagePattern":"(.+?) (.+?) keys must be ECKey instances\\.","errorType":"exception","errorClass":"InvalidKeyException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java","lineNumber":414,"sourceCode":"                if (encoded != null) {\n                    Arrays.fill(encoded, (byte) 0);\n                }\n            }\n\n        } else { //EC or RSA\n\n            if (signing) {\n                if (!(key instanceof PrivateKey)) {\n                    String msg = familyName + \" signing keys must be PrivateKey instances.\";\n                    throw new InvalidKeyException(msg);\n                }\n            }\n\n            if (isEllipticCurve()) {\n\n                if (!(key instanceof ECKey)) {\n                    String msg = familyName + \" \" + keyType(signing) + \" keys must be ECKey instances.\";\n                    throw new InvalidKeyException(msg);\n                }\n\n                ECKey ecKey = (ECKey) key;\n                int size = ecKey.getParams().getOrder().bitLength();\n                if (size < this.minKeyLength) {\n                    String msg = \"The \" + keyType(signing) + \" key's size (ECParameterSpec order) is \" + size +\n                            \" bits which is not secure enough for the \" + name() + \" algorithm.  The JWT \" +\n                            \"JWA Specification (RFC 7518, Section 3.4) states that keys used with \" +\n                            name() + \" MUST have a size >= \" + this.minKeyLength +\n                            \" bits.  Consider using the \" + Keys.class.getName() + \" class's \" +\n                            \"'keyPairFor(SignatureAlgorithm.\" + name() + \")' method to create a key pair guaranteed \" +\n                            \"to be secure enough for \" + name() + \".  See \" +\n                            \"https://tools.ietf.org/html/rfc7518#section-3.4 for more information.\";\n                    throw new WeakKeyException(msg);\n                }\n\n            } else { //RSA\n","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java#L396-L432","documentation":"Type guard in SignatureAlgorithm.assertValid: for elliptic-curve algorithms (ES256/ES384/ES512), the key must implement io.jsonwebtoken.ECKey (exposing ECParameterSpec) so the curve order can be size-checked. A PrivateKey of another type (e.g. RSAKey) or an EC PrivateKey that does not implement the ECKey interface is rejected with InvalidKeyException.","triggerScenarios":"Thrown at api/src/main/java/io/jsonwebtoken/SignatureAlgorithm.java:414 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use an EC key pair from Keys.keyPairFor(SignatureAlgorithm.ES256) — the returned keys implement ECKey.","If you hold a raw java.security.interfaces.ECPrivateKey, adapt or load it such that it implements io.jsonwebtoken.ECKey (e.g. via DefaultEcKey or a keystore path jjwt supports).","Verify you are not mixing families: RSA keys must go to RS*/PS* algorithms, EC keys to ES*."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}