{"record":{"id":"3e8b8ac7e550c514","repo":"gchq/CyberChef","slug":"signature-format-could-not-be-detected-3e8b8a","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/ECDSAVerify.mjs","lineNumber":119,"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 to ASN.1 signature\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":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ECDSAVerify.mjs#L101-L137","documentation":"Thrown in ECDSAVerify.run from the same Auto-detection logic as ECDSASignatureConversion: inputFormat starts as 'Auto', a JSON.parse probe (Raw JSON) and a fromBase64 URL-safe probe (JSON Web Signature) both silently fail, and the switch hits case 'Auto'. The signature was neither a JSON object nor a base64url concatenation, so its format could not be auto-detected.","triggerScenarios":"Input Format is 'Auto' and the signature is an ASN.1 HEX string (Auto does not recognise ASN.1 hex), malformed JSON, or standard base64 rather than base64url. Both probes swallow errors, leaving inputFormat untouched.","commonSituations":"Pasting ASN.1 HEX while on Auto; using +/ base64 instead of -_; truncated JSON; trailing whitespace breaking base64.","solutions":["Set Input Format explicitly to the format you have (ASN.1 HEX / P1363 HEX / Raw JSON / JSON Web Signature).","For JWS, use base64url encoding (- and _, strip padding).","For Raw JSON, supply valid JSON with r and s.","Trim whitespace from the signature."],"exampleFix":"// before\nverifyRun(p1363HexSig, ['Auto', ...]);   // Auto cannot detect P1363 hex\n// after\nverifyRun(p1363HexSig, ['P1363 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\";\n  throw new Error(\"set the signature format explicitly\");\n}","typeGuard":null,"tryCatchPattern":"try { verify(sig, [\"Auto\", ...]); }\ncatch (e) { if (String(e).includes(\"format could not be detected\")) verify(sig, [\"ASN.1 HEX\", ...]); else throw e; }","preventionTips":["Do not use Auto for ASN.1 HEX; Auto only knows Raw JSON and base64url.","Use base64url for JWS; trim whitespace from the signature."],"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"}