{"record":{"id":"e24a5799156856e5","repo":"jwtk/jjwt","slug":"unrecognized-jwa-ec-curve-id-jwacurveid","errorCode":null,"errorMessage":"Unrecognized JWA EC curve id '${jwaCurveId}'","messagePattern":"Unrecognized JWA EC curve id '(.+?)'","errorType":"validation","errorClass":"UnsupportedKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/AbstractEcJwkFactory.java","lineNumber":37,"sourceCode":"import io.jsonwebtoken.impl.lang.Converters;\nimport io.jsonwebtoken.impl.lang.Parameter;\nimport io.jsonwebtoken.io.Encoders;\nimport io.jsonwebtoken.security.Jwk;\nimport io.jsonwebtoken.security.UnsupportedKeyException;\n\nimport java.math.BigInteger;\nimport java.security.Key;\nimport java.security.interfaces.ECKey;\nimport java.security.spec.EllipticCurve;\nimport java.util.Set;\n\nabstract class AbstractEcJwkFactory<K extends Key & ECKey, J extends Jwk<K>> extends AbstractFamilyJwkFactory<K, J> {\n\n    protected static ECCurve getCurveByJwaId(String jwaCurveId) {\n        ECCurve curve = ECCurve.findById(jwaCurveId);\n        if (curve == null) {\n            String msg = \"Unrecognized JWA EC curve id '\" + jwaCurveId + \"'\";\n            throw new UnsupportedKeyException(msg);\n        }\n        return curve;\n    }\n\n    /**\n     * https://tools.ietf.org/html/rfc7518#section-6.2.1.2 indicates that this algorithm logic is defined in\n     * http://www.secg.org/sec1-v2.pdf Section 2.3.5.\n     *\n     * @param curve      EllipticCurve\n     * @param coordinate EC point coordinate (e.g. x or y) on the {@code curve}\n     * @return A base64Url-encoded String representing the EC field element per the RFC format\n     */\n    // Algorithm defined in http://www.secg.org/sec1-v2.pdf Section 2.3.5\n    static String toOctetString(EllipticCurve curve, BigInteger coordinate) {\n        byte[] bytes = Converters.BIGINT_UBYTES.applyTo(coordinate);\n        int fieldSizeInBits = curve.getField().getFieldSize();\n        int mlen = Bytes.length(fieldSizeInBits);\n        bytes = Bytes.prepad(bytes, mlen);","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/AbstractEcJwkFactory.java#L19-L55","documentation":"JJWT looks up an ECCurve enum instance by the JWA curve id (e.g. 'P-256', 'P-384', 'P-521', 'secp256k1') when building or parsing an EC JWK. If the id does not match any known curve, an UnsupportedKeyException is thrown. This means the key material references a curve the library does not recognize.","triggerScenarios":"Parsing or creating an EC JWK whose 'crv' member is misspelled, omitted variants, or a curve unsupported by the JJWT version (e.g. 'secp256k1' on versions lacking Ed/EC secp support, or lowercase 'p-256').","commonSituations":"Hand-written JWK JSON with a wrong crv value; keys generated with an exotic curve then fed to JJWT; older JJWT versions used against newer key sets; case-sensitivity mistakes.","solutions":["Use a JWA-standard curve id exactly: P-256, P-384, P-521, or secp256k1 (if supported).","Regenerate the key with a supported curve, e.g. KeyPairGenerator.getInstance('EC') initialized with ECGenParameterSpec('secp256r1').","Upgrade JJWT to a version that supports your curve.","Normalize case before passing the curve id."],"exampleFix":"// before\njwk.put(\"crv\", \"p256\");\n// after\njwk.put(\"crv\", \"P-256\");","handlingStrategy":"validation","validationCode":"boolean supported = jwk.getString(\"crv\").matches(\"P-(256|384|521)|secp256k1\");\nif (!supported) throw new IllegalArgumentException(\"Unsupported EC curve: \" + jwk.getString(\"crv\"));","typeGuard":"boolean isSupportedCurve(String crv) { return \"P-256\".equals(crv) || \"P-384\".equals(crv) || \"P-521\".equals(crv) || \"secp256k1\".equals(crv); }","tryCatchPattern":"try { curve = getCurveByJwaId(crv); }\ncatch (UnsupportedKeyException e) { log.error(\"Unsupported curve {}\", crv); return Result.unsupported(e); }","preventionTips":["Only use JWA-standard curve ids (P-256, P-384, P-521).","Keep crv values case-sensitive and exact.","Upgrade JJWT before adopting newer curves.","Validate crv at your JSON-schema boundary."],"tags":["jwk","ec-curve","unsupported-key","jjwt"],"backgroundTag":"invalid-enum-value","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"}