{"record":{"id":"091d0bddc03324a2","repo":"gchq/CyberChef","slug":"unknown-padding-type-padding-091d0b","errorCode":null,"errorMessage":"Unknown padding type: ${padding}","messagePattern":"Unknown padding type: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/RC6.mjs","lineNumber":386,"sourceCode":"                paddedMessage.push(0);\n            }\n            break;\n\n        case \"RANDOM\":\n            for (let i = 0; i < nPadding; i++) {\n                paddedMessage.push(Math.floor(Math.random() * 256));\n            }\n            break;\n\n        case \"BIT\":\n            paddedMessage.push(0x80);\n            for (let i = 1; i < nPadding; i++) {\n                paddedMessage.push(0);\n            }\n            break;\n\n        default:\n            throw new OperationError(`Unknown padding type: ${padding}`);\n    }\n\n    return paddedMessage;\n}\n\n/**\n * Remove padding from message\n * @param {number[]} message - Padded message\n * @param {string} padding - Padding type (\"NO\", \"PKCS5\", \"ZERO\", \"RANDOM\", \"BIT\")\n * @param {number} blockSize - Block size in bytes\n * @returns {number[]} - Unpadded message\n */\nfunction removePadding(message, padding, blockSize) {\n    if (message.length === 0) return message;\n\n    switch (padding) {\n        case \"NO\":\n        case \"ZERO\":","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/RC6.mjs#L368-L404","documentation":"Thrown by RC6.applyPadding when the `padding` argument matches none of the handled cases ('NO','PKCS5','ZERO','RANDOM','BIT'). Indicates a typo, an unsupported scheme, or an undefined value.","triggerScenarios":"Calling encryptRC6/decryptRC6 with a padding string outside the supported set, e.g. 'PKCS7', 'ISO10126', 'ANSIX923', '', or undefined (the default parameter is 'PKCS5' but an explicit undefined passed positionally overrides nothing — explicit bad strings do hit it).","commonSituations":"Confusing PKCS5 with PKCS7; passing a padding name from a different library; UI dropdown value renamed; forgotten argument shifting positions.","solutions":["Use one of the supported values exactly: 'NO','PKCS5','ZERO','RANDOM','BIT'.","If you need PKCS7, note that for RC6's 16-byte block PKCS5 and PKCS7 are equivalent — use 'PKCS5'.","Validate the padding value against the allowed list before calling."],"exampleFix":"// before\nencryptRC6(msg, key, iv, 'CBC', 'PKCS7');\n// after\nencryptRC6(msg, key, iv, 'CBC', 'PKCS5');","handlingStrategy":"validation","validationCode":"const RC6_PADDINGS = new Set(['NO','PKCS5','ZERO','RANDOM','BIT']);\nif (!RC6_PADDINGS.has(padding)) {\n  throw new Error(`Unknown RC6 padding '${padding}'`);\n}","typeGuard":"function isRc6Padding(p) {\n  return ['NO','PKCS5','ZERO','RANDOM','BIT'].includes(p);\n}","tryCatchPattern":"try {\n  return encryptRC6(message, key, iv, mode, padding, rounds, w);\n} catch (e) {\n  if (e instanceof OperationError && /Unknown padding type/.test(e.message)) {\n    return encryptRC6(message, key, iv, mode, 'PKCS5', rounds, w);\n  }\n  throw e;\n}","preventionTips":["Whitelist the padding value at the call site.","Remember PKCS5 and PKCS7 are equivalent at RC6's 16-byte block — use 'PKCS5'.","Map padding names from other libraries to this set explicitly."],"tags":["crypto","rc6","padding","validation","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}