{"record":{"id":"139dfea2b19b2012","repo":"jwtk/jjwt","slug":"ecpublickey-s-ecpoint-does-not-exist-on-elliptic-c","errorCode":null,"errorMessage":"ECPublicKey's ECPoint does not exist on elliptic curve '%s' and may not be used to create '%s' JWKs.","messagePattern":"ECPublicKey's ECPoint does not exist on elliptic curve '(.+?)' and may not be used to create '(.+?)' JWKs\\.","errorType":"exception","errorClass":"io.jsonwebtoken.security.InvalidKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/EcPublicJwkFactory.java","lineNumber":79,"sourceCode":"        if (c == null) {\n            throw new InvalidKeyException(UNSUPPORTED_CURVE_MSG);\n        }\n        return c.getId();\n    }\n\n    @Override\n    protected EcPublicJwk createJwkFromKey(JwkContext<ECPublicKey> ctx) {\n\n        ECPublicKey key = ctx.getKey();\n\n        ECParameterSpec spec = key.getParams();\n        EllipticCurve curve = spec.getCurve();\n        ECPoint point = key.getW();\n\n        String curveId = getJwaIdByCurve(curve);\n        if (!ECCurve.contains(curve, point)) {\n            String msg = keyContainsErrorMessage(curveId);\n            throw new InvalidKeyException(msg);\n        }\n\n        ctx.put(DefaultEcPublicJwk.CRV.getId(), curveId);\n\n        String x = toOctetString(curve, point.getAffineX());\n        ctx.put(DefaultEcPublicJwk.X.getId(), x);\n\n        String y = toOctetString(curve, point.getAffineY());\n        ctx.put(DefaultEcPublicJwk.Y.getId(), y);\n\n        return new DefaultEcPublicJwk(ctx);\n    }\n\n    @Override\n    protected EcPublicJwk createJwkFromValues(final JwkContext<ECPublicKey> ctx) {\n\n        ParameterReadable reader = new RequiredParameterReader(ctx);\n        String curveId = reader.get(DefaultEcPublicJwk.CRV);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/EcPublicJwkFactory.java#L61-L97","documentation":"EcPublicJwkFactory.createJwkFromKey verifies that the ECPublicKey's public point W actually lies on the declared elliptic curve before producing a JWK. If ECCurve.contains(curve, point) fails, the key is mathematically invalid for that curve and could be an invalid-curve attack vector, so creation is rejected.","triggerScenarios":"Building a JWK from an ECPublicKey whose W point is not on its declared curve — e.g. hand-constructed ECPublicKeySpec, corrupted keystores, or maliciously supplied keys.","commonSituations":"Manually constructing public keys from raw coordinates with mismatched parameters; keys tampered with in transit; unit-test fixtures with invented points.","solutions":["Generate EC key pairs with KeyPairGenerator rather than constructing points manually.","Validate the point satisfies the curve equation before building the key: check with ECCurve or a small BigInteger check y^2 = x^3 + ax + b (mod p).","Re-export or re-import the key from a trusted source if the key material may be corrupted.","Verify keys received from untrusted parties before use."],"exampleFix":"// before\nECPoint badPoint = new ECPoint(x, y); // y not on curve\nECPublicKeySpec spec = new ECPublicKeySpec(badPoint, params);\nKeyFactory kf = KeyFactory.getInstance(\"EC\");\nECPublicKey key = (ECPublicKey) kf.generatePublic(spec);\n// after\n// generate a guaranteed-valid pair instead\nKeyPairGenerator kg = KeyPairGenerator.getInstance(\"EC\");\nkg.initialize(new ECGenParameterSpec(\"secp256r1\"));\nECPublicKey key = (ECPublicKey) kg.generateKeyPair().getPublic();","handlingStrategy":"validation","validationCode":"BigInteger p = ((ECFieldFp) curve.getField()).getP();\nboolean onCurve = point.getAffineY().pow(2).subtract(point.getAffineX().pow(3).add(curve.getA().multiply(point.getAffineX())).add(curve.getB())).mod(p).signum() == 0;\nif (!onCurve) throw new IllegalArgumentException(\"ECPoint not on curve\");","typeGuard":null,"tryCatchPattern":"try {\n    Jwk<?> jwk = Jwks.builder().setKey(ecPublicKey).build();\n} catch (io.jsonwebtoken.security.InvalidKeyException e) {\n    // regenerate or re-source the key pair\n}","preventionTips":["Generate EC pairs with KeyPairGenerator instead of hand-built ECPublicKeySpec","Validate externally supplied EC points before trusting them"],"tags":["java","jjwt","ec","jwk","point-validation"],"backgroundTag":"invalid-curve-point","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"}