mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Add ECB/NoPadding and CBC/NoPadding Encryption
This commit is contained in:
parent
d3357d2acd
commit
23de98f892
1 changed files with 19 additions and 1 deletions
|
@ -66,6 +66,14 @@ class AESEncrypt extends Operation {
|
||||||
{
|
{
|
||||||
name: "ECB",
|
name: "ECB",
|
||||||
off: [5]
|
off: [5]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "CBC/NoPadding",
|
||||||
|
off: [5]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ECB/NoPadding",
|
||||||
|
off: [5]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -98,7 +106,8 @@ class AESEncrypt extends Operation {
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
||||||
mode = args[2],
|
mode = args[2].substring(0, 3),
|
||||||
|
noPadding = args[2].endsWith("NoPadding"),
|
||||||
inputType = args[3],
|
inputType = args[3],
|
||||||
outputType = args[4],
|
outputType = args[4],
|
||||||
aad = Utils.convertToByteString(args[5].string, args[5].option);
|
aad = Utils.convertToByteString(args[5].string, args[5].option);
|
||||||
|
@ -114,11 +123,20 @@ The following algorithms will be used based on the size of the key:
|
||||||
|
|
||||||
input = Utils.convertToByteString(input, inputType);
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
// Handle NoPadding modes
|
||||||
|
if (noPadding && input.length % 16 !== 0) {
|
||||||
|
throw new OperationError("Input length must be a multiple of 16 bytes for NoPadding modes.");
|
||||||
|
}
|
||||||
const cipher = forge.cipher.createCipher("AES-" + mode, key);
|
const cipher = forge.cipher.createCipher("AES-" + mode, key);
|
||||||
cipher.start({
|
cipher.start({
|
||||||
iv: iv,
|
iv: iv,
|
||||||
additionalData: mode === "GCM" ? aad : undefined
|
additionalData: mode === "GCM" ? aad : undefined
|
||||||
});
|
});
|
||||||
|
if (noPadding) {
|
||||||
|
cipher.mode.pad = function(output, options) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
cipher.update(forge.util.createBuffer(input));
|
cipher.update(forge.util.createBuffer(input));
|
||||||
cipher.finish();
|
cipher.finish();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue