{"record":{"id":"c09c1e0ab3ad12b3","repo":"gchq/CyberChef","slug":"signature-format-could-not-be-detected","errorCode":null,"errorMessage":"Signature format could not be detected","messagePattern":"Signature format could not be detected","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ECDSASignatureConversion.mjs","lineNumber":98,"sourceCode":"                } else {\n                    inputFormat = \"P1363 HEX\";\n                }\n            }\n        }\n\n        let inputBase64;\n        if (inputFormat === \"Auto\") {\n            try {\n                inputBase64 = fromBase64(input, \"A-Za-z0-9-_\", false);\n                inputFormat = \"JSON Web Signature\";\n            } catch {}\n        }\n\n        // convert input to ASN.1 hex\n        let signatureASN1Hex;\n        switch (inputFormat) {\n            case \"Auto\":\n                throw new OperationError(\"Signature format could not be detected\");\n            case \"ASN.1 HEX\":\n                signatureASN1Hex = input;\n                break;\n            case \"P1363 HEX\":\n                signatureASN1Hex = r.KJUR.crypto.ECDSA.concatSigToASN1Sig(input);\n                break;\n            case \"JSON Web Signature\":\n                if (!inputBase64) inputBase64 = fromBase64(input, \"A-Za-z0-9-_\");\n                signatureASN1Hex = r.KJUR.crypto.ECDSA.concatSigToASN1Sig(toHexFast(inputBase64));\n                break;\n            case \"Raw JSON\": {\n                if (!inputJson) inputJson = JSON.parse(input);\n                if (!inputJson.r) {\n                    throw new OperationError('No \"r\" value in the signature JSON');\n                }\n                if (!inputJson.s) {\n                    throw new OperationError('No \"s\" value in the signature JSON');\n                }","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ECDSASignatureConversion.mjs#L80-L116","documentation":"Thrown in ECDSASignatureConversion.run when inputFormat is still 'Auto' after auto-detection. In Auto the code first tries JSON.parse (Raw JSON) then fromBase64 with the URL-safe alphabet (JSON Web Signature); both probes are in try/catch that silently swallow errors. If neither sets inputFormat, the switch hits case 'Auto'. The input matched neither a JSON object nor a base64url concatenation signature.","triggerScenarios":"Input Format is 'Auto' and the signature is not valid JSON, not valid base64url, or is an ASN.1 HEX string (Auto cannot identify ASN.1 hex because it looks like arbitrary hex). The JSON and base64 probes both swallow their failures, leaving inputFormat unchanged.","commonSituations":"Pasting an ASN.1 HEX signature while leaving format on Auto (Auto recognises only Raw JSON and JWS); malformed/truncated JSON; standard (+/) base64 instead of URL-safe (-_) which the fromBase64 alphabet rejects.","solutions":["Switch Input Format from 'Auto' to the explicit format you have (ASN.1 HEX / P1363 HEX / Raw JSON / JSON Web Signature).","For JWS, ensure the signature is base64url (- and _, no padding) not standard base64.","For Raw JSON, ensure valid JSON with r and s fields.","Trim stray whitespace/newlines from the signature."],"exampleFix":"// before: ASN.1 hex signature with format on Auto -> throws\nrun(asn1HexSig, ['Auto', ...]);\n// after: declare the format explicitly\nrun(asn1HexSig, ['ASN.1 HEX', ...]);","handlingStrategy":"validation","validationCode":"function detectSigFormat(sig) {\n  try { const o = JSON.parse(sig); if (o && typeof o === \"object\") return \"Raw JSON\"; } catch {}\n  try { fromBase64(sig, \"A-Za-z0-9-_\", false); return \"JSON Web Signature\"; } catch {}\n  if (/^[0-9a-fA-F]+$/.test(sig)) return \"ASN.1 HEX\"; // best-effort; let user confirm\n  throw new Error(\"could not auto-detect; set the format explicitly\");\n}","typeGuard":null,"tryCatchPattern":"try { run(sig, [\"Auto\", ...]); }\ncatch (e) { if (String(e).includes(\"format could not be detected\")) run(sig, [\"ASN.1 HEX\", ...]); else throw e; }","preventionTips":["Avoid Auto for ASN.1 HEX input - Auto recognises only Raw JSON and base64url JWS.","Use base64url (- and _, no padding) for JWS signatures.","Prefer setting Input Format explicitly."],"tags":["crypto","ecdsa","signature","format-detection","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}