gchq/CyberChef · error · OperationError
Invalid key length: bytes. Ascon-AEAD128 requires a key of…
Error message
Invalid key length: ${key.length} bytes.
Ascon-AEAD128 requires a key of exactly 16 bytes (128 bits). What it means
Thrown by AsconDecrypt.run when the supplied key is not exactly 16 bytes (128 bits). Ascon-AEAD128 (the NIST-LWC standardized variant implemented here) fixes the key size at 128 bits, so the operation hard-validates key.length === 16 before invoking JsAscon.decrypt. The key is converted via Utils.convertToByteArray using the chosen input option (Hex, Base64, UTF8, etc.), so the length is measured in decoded bytes, not input characters.
Solutions
- Provide exactly 16 bytes of key material (32 hex chars, or ~22 base64 chars).
- If you only have a passphrase, hash it to 16 bytes first (e.g. SHA-256 then truncate, or use a KDF) before Ascon.
- Confirm the input option matches your key encoding (Hex vs UTF8) so the byte count is what you expect.
Example fix
// before - 32 hex chars = 16 bytes? No: 'abcd...' of wrong length
chef.asconDecrypt(ct, { key: "short", keyOption: "UTF8" });
// after - 32 hex chars = exactly 16 bytes
chef.asconDecrypt(ct, { key: "00112233445566778899aabbccddeeff", keyOption: "Hex" }); Defensive patterns
Strategy: validation
Validate before calling
import Utils from "src/core/Utils.mjs";
function assertAsconKey(keyStr, keyOption) {
const bytes = Utils.convertToByteArray(keyStr, keyOption);
if (bytes.length !== 16) {
throw new Error(`Ascon key must be 16 bytes, got ${bytes.length}`);
}
return bytes;
}
assertAsconKey(key, keyOption); Type guard
function isExactlyNBytes(s, option, n) {
// caller must decode; structural guard for hex:
if (option === "Hex") return /^[0-9a-f]{2*n}$/i.test(s);
return false; // decode and measure for other options
} Prevention
- Use exactly 16 bytes (32 hex chars) for the Ascon key.
- Derive keys from passphrases with a KDF before Ascon.
- Verify the input option matches the key encoding.
When it happens
Trigger: Supplying a 32-byte key (common when reusing an AES-256 key), a short passphrase as UTF-8, a hex string of wrong length, or a base64 value that decodes to != 16 bytes.
Common situations: Reusing an AES-256 key or SHA-256 digest as the Ascon key; pasting a human passphrase expecting it to be padded; hex/base64 miscount causing off-by-one byte length.
Related errors
- Invalid key length: bytes. Ascon-AEAD128 requires a key of…
- Invalid key length: bytes. Ascon-Mac requires a key of…
- Invalid nonce length
- Invalid nonce length
- Unable to decrypt: authentication failed. The ciphertext…
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/72fe059d452789a9.
Report an issue: GitHub.
Appendix: source
Thrown at src/core/operations/AsconDecrypt.mjs:76
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @throws {OperationError} if invalid key or nonce length, or authentication fails
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
nonce = Utils.convertToByteArray(args[1].string, args[1].option),
ad = Utils.convertToByteArray(args[2].string, args[2].option),
inputType = args[3],
outputType = args[4];
if (key.length !== 16) {
throw new OperationError(`Invalid key length: ${key.length} bytes.
Ascon-AEAD128 requires a key of exactly 16 bytes (128 bits).`);
}
if (nonce.length !== 16) {
throw new OperationError(`Invalid nonce length: ${nonce.length} bytes.
Ascon-AEAD128 requires a nonce of exactly 16 bytes (128 bits).`);
}
// Convert input to byte array
const inputData = Utils.convertToByteArray(input, inputType);
const keyUint8 = new Uint8Array(key);
const nonceUint8 = new Uint8Array(nonce);
const adUint8 = new Uint8Array(ad);
const ciphertextUint8 = new Uint8Array(inputData);
View on GitHub (pinned to 4290ea7539)