Added padding option to AESencrypt/decrypt

Added new padding option to AESencryption/decryption that asks if they want padding or not.
This commit is contained in:
Storms-Engineering 2019-10-31 08:38:20 -08:00
parent b785f4482a
commit 7a7afebbd9
2 changed files with 16 additions and 6 deletions

View file

@ -54,6 +54,11 @@ class AESDecrypt extends Operation {
"type": "option", "type": "option",
"value": ["Raw", "Hex"] "value": ["Raw", "Hex"]
}, },
{
"name": "Padding",
"type": "option",
"value": ["No", "Yes"]
},
{ {
"name": "GCM Tag", "name": "GCM Tag",
"type": "toggleString", "type": "toggleString",
@ -76,8 +81,8 @@ class AESDecrypt extends Operation {
mode = args[2], mode = args[2],
inputType = args[3], inputType = args[3],
outputType = args[4], outputType = args[4],
gcmTag = Utils.convertToByteString(args[5].string, args[5].option); gcmTag = Utils.convertToByteString(args[6].string, args[6].option);
var padding = args[5];
if ([16, 24, 32].indexOf(key.length) < 0) { if ([16, 24, 32].indexOf(key.length) < 0) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
@ -95,8 +100,8 @@ The following algorithms will be used based on the size of the key:
tag: gcmTag tag: gcmTag
}); });
decipher.update(forge.util.createBuffer(input)); decipher.update(forge.util.createBuffer(input));
const result = decipher.finish(); const result = (padding === "No") ? decipher.finish() : decipher.finish(() => true);
console.log(result);
if (result) { if (result) {
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes(); return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
} else { } else {

View file

@ -53,6 +53,11 @@ class AESEncrypt extends Operation {
"name": "Output", "name": "Output",
"type": "option", "type": "option",
"value": ["Hex", "Raw"] "value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["No", "Yes"]
} }
]; ];
} }
@ -70,7 +75,7 @@ class AESEncrypt extends Operation {
mode = args[2], mode = args[2],
inputType = args[3], inputType = args[3],
outputType = args[4]; outputType = args[4];
var padding = args[5];
if ([16, 24, 32].indexOf(key.length) < 0) { if ([16, 24, 32].indexOf(key.length) < 0) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
@ -85,7 +90,7 @@ The following algorithms will be used based on the size of the key:
const cipher = forge.cipher.createCipher("AES-" + mode, key); const cipher = forge.cipher.createCipher("AES-" + mode, key);
cipher.start({iv: iv}); cipher.start({iv: iv});
cipher.update(forge.util.createBuffer(input)); cipher.update(forge.util.createBuffer(input));
cipher.finish(); (padding === "No") ? cipher.finish() : cipher.finish(() => true);
if (outputType === "Hex") { if (outputType === "Hex") {
if (mode === "GCM") { if (mode === "GCM") {