{"record":{"id":"512db51639ec4c21","repo":"jwtk/jjwt","slug":"unrecognized-edwards-curve-key-key","errorCode":null,"errorMessage":"Unrecognized Edwards Curve key: [${key}]","messagePattern":"Unrecognized Edwards Curve key: \\[(.+?)\\]","errorType":"exception","errorClass":"io.jsonwebtoken.security.InvalidKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/EdwardsCurve.java","lineNumber":378,"sourceCode":"    }\n\n    private static int findOidTerminalNode(byte[] encoded) {\n        int index = Bytes.indexOf(encoded, ASN1_OID_PREFIX);\n        if (index > -1) {\n            index = index + ASN1_OID_PREFIX.length;\n            if (index < encoded.length) {\n                return encoded[index];\n            }\n        }\n        return -1;\n    }\n\n    public static EdwardsCurve forKey(Key key) {\n        Assert.notNull(key, \"Key cannot be null.\");\n        EdwardsCurve curve = findByKey(key);\n        if (curve == null) {\n            String msg = \"Unrecognized Edwards Curve key: [\" + KeysBridge.toString(key) + \"]\";\n            throw new InvalidKeyException(msg);\n        }\n        //TODO: assert key exists on discovered curve via equation\n        return curve;\n    }\n\n    @SuppressWarnings(\"UnusedReturnValue\")\n    static <K extends Key> K assertEdwards(K key) {\n        forKey(key); // will throw UnsupportedKeyException if the key is not an Edwards key\n        return key;\n    }\n}\n","sourceCodeStart":360,"sourceCodeEnd":390,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/EdwardsCurve.java#L360-L390","documentation":"EdwardsCurve.forKey identifies which Edwards curve (Ed25519, Ed448, X25519, X448) a key belongs to by inspecting its algorithm and encoded format. If findByKey cannot match the key to any known Edwards curve, this InvalidKeyException is thrown, since the key cannot be used for any Edwards-curve operation.","triggerScenarios":"Passing a non-Edwards key (RSA, EC, HMAC) to APIs expecting OKP keys — e.g. EdSignatureAlgorithm sign/verify, ECDH with OKP recipient — or an Edwards key whose encoded form is unrecognizable to the JVM provider.","commonSituations":"Using an EC P-256 key where an Ed25519 key is required; a key loaded from a provider that reports an unfamiliar algorithm name; a custom/foreign Key implementation that doesn't expose recognizable encoded bytes.","solutions":["Ensure you pass an Ed25519/Ed448/X25519/X448 key generated via Jwts.SIG.keyPair() or a compatible JCE provider.","Log KeysBridge.toString(key) (shown in the message) to see the key's algorithm/format and confirm it is an OKP key.","Install a provider that supports Edwards curves (e.g. Java 15+ built-in or BouncyCastle) so keys have the expected algorithm names.","Regenerate the key pair if it was produced by a non-standard implementation."],"exampleFix":"// before: EC key used where an OKP key is required\nKeyPair kp = KeyPairGenerator.getInstance(\"EC\").generateKeyPair();\nJwts.builder().signWith(kp.getPrivate(), Jwts.SIG.EdDSA);\n// after\nKeyPair kp = Jwts.SIG.EdDSA.keyPair().build();\nJwts.builder().signWith(kp.getPrivate(), Jwts.SIG.EdDSA);","handlingStrategy":"type-guard","validationCode":"EdwardsCurve curve = EdwardsCurve.findByKey(key);\nif (curve == null) {\n  throw new IllegalArgumentException(\"Not an Edwards curve key: \" + key.getAlgorithm());\n}","typeGuard":"boolean isEdwardsKey(java.security.Key k) {\n  String a = k.getAlgorithm();\n  return a.equals(\"Ed25519\") || a.equals(\"Ed448\") || a.equals(\"X25519\") || a.equals(\"X448\");\n}","tryCatchPattern":"try {\n  Jwts.builder().signWith(key, Jwts.SIG.EdDSA).compact();\n} catch (InvalidKeyException e) {\n  // unrecognized key: regenerate an OKP key pair\n}","preventionTips":["Generate OKP keys with Jwts.SIG.*.keyPair() rather than generic generators","Check key.getAlgorithm() before Edwards operations","Ensure a JCE provider supporting Edwards curves is registered"],"tags":["edwards-curve","key-type","invalid-key"],"backgroundTag":"invalid-key-type","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}