{"record":{"id":"68a90f8de44fdf27","repo":"gchq/CyberChef","slug":"unable-to-decrypt-authentication-failed-the-ciph","errorCode":null,"errorMessage":"Unable to decrypt: authentication failed. The ciphertext, key, nonce, or associated data may be incorrect or tampered with.","messagePattern":"Unable to decrypt: authentication failed\\. The ciphertext, key, nonce, or associated data may be incorrect or tampered with\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/AsconDecrypt.mjs","lineNumber":106,"sourceCode":"        const inputData = Utils.convertToByteArray(input, inputType);\n\n        const keyUint8 = new Uint8Array(key);\n        const nonceUint8 = new Uint8Array(nonce);\n        const adUint8 = new Uint8Array(ad);\n        const ciphertextUint8 = new Uint8Array(inputData);\n\n        try {\n            // Decrypt (returns Uint8Array containing plaintext)\n            const plaintext = JsAscon.decrypt(keyUint8, nonceUint8, adUint8, ciphertextUint8);\n\n            // Return in requested format\n            if (outputType === \"Hex\") {\n                return toHexFast(plaintext);\n            } else {\n                return Utils.arrayBufferToStr(Uint8Array.from(plaintext).buffer);\n            }\n        } catch (e) {\n            throw new OperationError(\"Unable to decrypt: authentication failed. The ciphertext, key, nonce, or associated data may be incorrect or tampered with.\");\n        }\n    }\n\n}\n\nexport default AsconDecrypt;\n","sourceCodeStart":88,"sourceCodeEnd":113,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/AsconDecrypt.mjs#L88-L113","documentation":"Thrown by AsconDecrypt.run when JsAscon.decrypt raises any exception during AEAD decryption. Ascon-AEAD128 is an authenticated cipher: it computes and verifies a tag over the ciphertext and associated data, and a mismatch (wrong key, wrong/modified nonce, tampered ciphertext, or mismatched associated data) causes the library to throw rather than emit garbage. The catch collapses every internal failure into this single authentication-failure message, hiding the specific reason by design.","triggerScenarios":"Any of: wrong key, wrong nonce, wrong/missing associated data (AD), truncated ciphertext (tag missing), or a single bit flip in the ciphertext/tag from corruption or copy error.","commonSituations":"Decrypting with a key that does not match the encryption key; AD set on encrypt but omitted on decrypt (or vice versa); ciphertext copied incompletely (missing the trailing tag bytes); nonce mismatch between sides.","solutions":["Verify the key and nonce exactly match those used to encrypt (both 16 bytes).","Ensure the associated data (AD) argument is identical on encrypt and decrypt, including empty vs absent.","Re-check that the full ciphertext including the authentication tag was copied without truncation.","Treat this error as authoritative: do not retry with tweaked parameters hoping for output."],"exampleFix":"// before - AD mismatch: encrypted with AD, decrypting without\nchef.asconDecrypt(ct, { key, nonce, ad: \"\" });\n\n// after - AD matches what was used at encryption\nchef.asconDecrypt(ct, { key, nonce, ad: \"header-v1\" });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const pt = chef.asconDecrypt(ct, { key, nonce, ad });\n} catch (e) {\n  if (e.message.includes(\"authentication failed\")) {\n    // expected on wrong key/nonce/ad/tampered ciphertext; do not retry blindly\n    throw new Error(\"Ascon authentication failed: verify key, nonce, and AD\");\n  }\n  throw e;\n}","preventionTips":["Transport key, nonce, and AD together with the ciphertext.","Keep AD identical on encrypt and decrypt (empty vs absent matters).","Copy the full ciphertext including the trailing tag.","Treat auth failure as definitive; never surface partial plaintext."],"tags":["crypto","aead","ascon","authentication"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}