{"record":{"id":"05f91d5730f8255e","repo":"gchq/CyberChef","slug":"invalid-input-format","errorCode":null,"errorMessage":"Invalid input format.","messagePattern":"Invalid input format\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ParseSSHHostKey.mjs","lineNumber":107,"sourceCode":"     * @returns {byteArray}\n     */\n    convertKeyToBinary(inputKey, inputFormat) {\n        const keyPattern = new RegExp(/^(?:ssh|ecdsa-sha2)\\S+\\s+(\\S*)/),\n            keyMatch = inputKey.match(keyPattern);\n\n        if (keyMatch) {\n            inputKey = keyMatch[1];\n        }\n\n        if (inputFormat === \"Auto\") {\n            inputFormat = this.detectKeyFormat(inputKey);\n        }\n        if (inputFormat === \"Hex\") {\n            return fromHex(inputKey);\n        } else if (inputFormat === \"Base64\") {\n            return fromBase64(inputKey, null, \"byteArray\");\n        } else {\n            throw new OperationError(\"Invalid input format.\");\n        }\n    }\n\n\n    /**\n     * Detects if the key is base64 or hex encoded\n     *\n     * @param {string} inputKey\n     * @returns {string}\n     */\n    detectKeyFormat(inputKey) {\n        const hexPattern = new RegExp(/^(?:[\\dA-Fa-f]{2}[ ,;:]?)+$/);\n        const b64Pattern = new RegExp(/^\\s*(?:[A-Za-z\\d+/]{4})+(?:[A-Za-z\\d+/]{2}==|[A-Za-z\\d+/]{3}=)?\\s*$/);\n\n        if (hexPattern.test(inputKey)) {\n            return \"Hex\";\n        } else if (b64Pattern.test(inputKey)) {\n            return \"Base64\";","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ParseSSHHostKey.mjs#L89-L125","documentation":"The Parse SSH Host Key operation's convertKeyToBinary method accepts 'Auto', 'Hex', or 'Base64' as the input format. After auto-detection resolves to a concrete format, only 'Hex' and 'Base64' are handled. This else-branch fires for any unrecognized format string. Since the UI dropdown constrains to three options, this only triggers with programmatic or hand-edited recipes.","triggerScenarios":"args[0] (inputFormat) is a string that is not 'Auto', 'Hex', or 'Base64' and does not resolve to either after detection. Occurs with a typo in a programmatically constructed recipe, or a hand-edited recipe JSON with an invalid format value.","commonSituations":"Recipe JSON is hand-edited with a misspelled format value. Recipe is built programmatically with an unvalidated format string. Recipe is copied from a different version or tool.","solutions":["Set the 'Input Format' argument to 'Auto', 'Base64', or 'Hex'","Validate the format argument programmatically before recipe execution"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const VALID_FORMATS = [\"Auto\", \"Base64\", \"Hex\"];\nif (!VALID_FORMATS.includes(args[0])) {\n  throw new Error(`Input format must be one of: ${VALID_FORMATS.join(\", \")}`);\n}","typeGuard":"function isSshKeyFormat(v) {\n  return v === \"Auto\" || v === \"Base64\" || v === \"Hex\";\n}","tryCatchPattern":null,"preventionTips":["Validate format arguments programmatically against the allowed values before recipe execution"],"tags":["ssh","key","argument-validation","format"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}