{"record":{"id":"8a233c1779fd4eab","repo":"gchq/CyberChef","slug":"err-8a233c","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GOSTEncrypt.mjs","lineNumber":145,"sourceCode":"            version: versionNum,\n            length: blockLength,\n            mode: \"ES\",\n            sBox: sBoxVal,\n            block: blockMode,\n            keyMeshing: keyMeshing,\n            padding: padding\n        };\n\n        try {\n            const Hex = CryptoGost.coding.Hex;\n            if (iv) algorithm.iv = Hex.decode(iv);\n\n            const cipher = GostEngine.getGostCipher(algorithm);\n            const out = Hex.encode(cipher.encrypt(Hex.decode(key), Hex.decode(input)));\n\n            return outputType === \"Hex\" ? out : Utils.byteArrayToChars(fromHex(out));\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default GOSTEncrypt;\n","sourceCodeStart":127,"sourceCodeEnd":152,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GOSTEncrypt.mjs#L127-L152","documentation":"Catch-all around the crypto-gost-js engine calls in GOST Encrypt, re-raising any library error as an OperationError. Common underlying causes: key not 256 bits, IV missing/wrong length for the chosen block mode, invalid sBox for the 1989 variant, non-hex input where Input type is Hex, or engine parameter incompatibility.","triggerScenarios":"Key shorter/longer than 32 bytes; CBC/CFB/OFB/CTR selected with an IV that isn't the block size; non-hex characters in input when Input type is Hex; an sBox value that the 1989 engine rejects.","commonSituations":"Interop with external GOST tooling that uses different defaults; pasting base64 keys into a Hex field; forgetting Kuznyechik needs a 16-byte IV vs Magma's 8 bytes.","solutions":["Provide a 32-byte (64-hex-digit) key.","Supply an IV matching the block size for non-ECB modes.","Match Input type to the real input encoding.","Inspect the preserved `err` to pinpoint the library failure."],"exampleFix":"// before: 8-byte IV with 128-bit Kuznyechik CBC\nargs = [key, \"0011223344556677\", \"Hex\", \"Hex\", \"GOST R 34.12 (Kuznyechik, 2015)\", \"E-A\", \"CBC\", \"NO\", \"PKCS5\"];\n// after: 16-byte IV\nargs = [key, \"00112233445566778899aabbccddeeff\", \"Hex\", \"Hex\", \"GOST R 34.12 (Kuznyechik, 2015)\", \"E-A\", \"CBC\", \"NO\", \"PKCS5\"];","handlingStrategy":"try-catch","validationCode":"if (hexKey.length !== 64) throw new Error(\"GOST key must be 32 bytes / 64 hex chars\");\nif (mode !== \"ECB\" && hexIv.length !== (blockBits/8)*2) throw new Error(`IV must be ${blockBits/8} bytes for ${mode}`);","typeGuard":"function isHex(s){return typeof s===\"string\"&&/^[0-9a-fA-F]*$/.test(s)&&s.length%2===0;}","tryCatchPattern":"try { chef.bake(input, recipe); }\ncatch (e) { if (/key|iv|length|sbox/i.test(e.message||\"\")) handleUserError(e); else throw e; }","preventionTips":["Use a 32-byte key and a block-size IV for non-ECB modes.","Match Input type to the real input encoding.","Inspect the wrapped err for the library's exact message."],"tags":["crypto","gost","cipher","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}