gchq/CyberChef · error · OperationError
Invalid hash
Error message
Invalid hash
What it means
Thrown by AnalyseHash.run when the input, after stripping all whitespace, does not match /^[a-f0-9]+$/i. The operation analyses a hash by its byte/bit length to suggest candidate algorithms, so it requires the input to be a contiguous hex string. Any non-hex character (a stray separator, a 0x prefix, a base64 hash, or trailing newline outside whitespace) causes rejection.
Source
Thrown at src/core/operations/AnalyseHash.mjs:44
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
input = input.replace(/\s/g, "");
let output = "",
possibleHashFunctions = [];
const byteLength = input.length / 2,
bitLength = byteLength * 8;
if (!/^[a-f0-9]+$/i.test(input)) {
throw new OperationError("Invalid hash");
}
output += "Hash length: " + input.length + "\n" +
"Byte length: " + byteLength + "\n" +
"Bit length: " + bitLength + "\n\n" +
"Based on the length, this hash could have been generated by one of the following hashing functions:\n";
switch (bitLength) {
case 4:
possibleHashFunctions = [
"Fletcher-4",
"Luhn algorithm",
"Verhoeff algorithm",
];
break;
case 8:
possibleHashFunctions = [
"Fletcher-8",View on GitHub (pinned to 4290ea7539)
Solutions
- Provide the hash as a pure hexadecimal string (only 0-9 and a-f/A-F).
- Remove any '0x' prefix, colons, dashes, or algorithm-name labels before the operation.
- If the hash is base64 or raw bytes, first convert it to hex with a 'From Base64' or 'To Hex' operation.
- Strip whitespace upstream; AnalyseHash already removes whitespace but will not remove other separators.
Example fix
// before
chef.analyseHash("sha256: e3b0c44298fc1c14...");
// after
chef.analyseHash("e3b0c44298fc1c14..."); Defensive patterns
Strategy: validation
Validate before calling
function assertHexString(hash) {
const clean = String(hash).replace(/\s/g, "");
if (!/^[a-f0-9]+$/i.test(clean) || clean.length === 0) {
throw new Error("Input must be a non-empty hex string");
}
return clean;
}
const hex = assertHexString(input); Type guard
function isHexString(s) {
const clean = String(s).replace(/\s/g, "");
return clean.length > 0 && /^[a-f0-9]+$/i.test(clean);
} Prevention
- Convert base64/raw hashes to hex before AnalyseHash.
- Strip algorithm-name labels and '0x' prefixes upstream.
- Avoid byte separators (colons/dashes) in the input.
When it happens
Trigger: Input containing characters outside [0-9a-fA-F] after whitespace removal: a '0x' prefix, colons/dashes between byte groups, a base64-encoded hash, mixed-case with non-hex letters like 'g-z', or an empty string.
Common situations: Pasting a hash that includes separators (aa:bb:cc...), feeding a base64 or raw binary hash instead of hex, copying a hash with a leading label like 'sha256: ...', or an upstream operation emitting a non-hex digest.
Related errors
- Invalid UUID
- ${err.toString()}
- Incorrect hash length
- ${err}
- Error: Invalid Base64 input length (${data.length}). Cannot
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/361815efd2432bc7.
Report an issue: GitHub.