{"record":{"id":"972ee71febd704bd","repo":"jwtk/jjwt","slug":"invalid-ecdsa-signature-format","errorCode":null,"errorMessage":"Invalid ECDSA signature format","messagePattern":"Invalid ECDSA signature format","errorType":"exception","errorClass":"io.jsonwebtoken.JwtException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/EcSignatureAlgorithm.java","lineNumber":253,"sourceCode":"                }\n            }\n        });\n    }\n\n    /**\n     * Transcodes the JCA ASN.1/DER-encoded signature into the concatenated\n     * R + S format expected by ECDSA JWS.\n     *\n     * @param derSignature The ASN1./DER-encoded. Must not be {@code null}.\n     * @param outputLength The expected length of the ECDSA JWS signature.\n     * @return The ECDSA JWS encoded signature.\n     * @throws JwtException If the ASN.1/DER signature format is invalid.\n     * @author Martin Treurnicht via <a href=\"https://github.com/jwtk/jjwt/commit/61510dfca58dd40b4b32c708935126785dcff48c\">61510dfca58dd40b4b32c708935126785dcff48c</a>\n     */\n    public static byte[] transcodeDERToConcat(final byte[] derSignature, int outputLength) throws JwtException {\n\n        if (derSignature.length < 8 || derSignature[0] != 48) {\n            throw new JwtException(\"Invalid ECDSA signature format\");\n        }\n\n        int offset;\n        if (derSignature[1] > 0) {\n            offset = 2;\n        } else if (derSignature[1] == (byte) 0x81) {\n            offset = 3;\n        } else {\n            throw new JwtException(\"Invalid ECDSA signature format\");\n        }\n\n        byte rLength = derSignature[offset + 1];\n\n        int i = rLength;\n        while ((i > 0) && (derSignature[(offset + 2 + rLength) - i] == 0)) {\n            i--;\n        }\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/EcSignatureAlgorithm.java#L235-L271","documentation":"JJWT's transcodeDERToConcat converts an ASN.1/DER ECDSA signature into the RFC 7518 R||S concatenation. The very first structural check requires the DER blob to be at least 8 bytes and to start with the SEQUENCE tag byte 0x30. A signature failing this basic shape check causes a JwtException('Invalid ECDSA signature format').","triggerScenarios":"Calling apply()/verify with a signature byte array shorter than 8 bytes or not beginning with 0x30 — i.e. not DER at all — for example a raw concat signature fed into a DER-parsing path, or random garbage/truncated bytes.","commonSituations":"Base64url-decoding the JWT signature segment and re-checking it manually with transcodeDERToConcat when it is already concat format; truncated storage of signature bytes; verifying tokens signed by non-JWS schemes.","solutions":["Confirm the input to transcodeDERToConcat is genuinely DER (starts with 0x30); raw JWS concat signatures must NOT be passed here","Check the signature's decoded length against the expected 64/96/132 bytes before transcoding — short arrays indicate truncation upstream","Regenerate the token from the trusted signer if the bytes are corrupted"],"exampleFix":"// before\nbyte[] raw = Base64.getUrlDecoder().decode(jwtSignatureSegment); // already R||S concat\nbyte[] der = EcSignatureAlgorithm.transcodeDERToConcat(raw, 64); // throws: not DER\n// after\nbyte[] raw = Base64.getUrlDecoder().decode(jwtSignatureSegment);\nif (raw.length != 64) throw new IllegalArgumentException(\"bad ES256 signature length\");\n// raw is already concat format; no transcoding needed","handlingStrategy":"validation","validationCode":"boolean looksLikeDer(byte[] sig) {\n  return sig != null && sig.length >= 8 && sig[0] == 0x30;\n}","typeGuard":null,"tryCatchPattern":"try {\n  byte[] concat = EcSignatureAlgorithm.transcodeDERToConcat(derSig, 64);\n} catch (JwtException e) {\n  throw new IllegalArgumentException(\"Input is not a DER ECDSA signature (expected 0x30-leading ASN.1)\", e);\n}","preventionTips":["Only call transcodeDERToConcat on signatures you know are DER-encoded","Check sig[0] == 0x30 and length >= 8 before transcoding","Keep a clear boundary: JWS tokens use concat signatures; only external DER input needs transcoding"],"tags":["jwt","ecdsa","der","signature-format"],"backgroundTag":"invalid-argument-format","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"}