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",
"value": ["Raw", "Hex"]
},
{
"name": "Padding",
"type": "option",
"value": ["No", "Yes"]
},
{
"name": "GCM Tag",
"type": "toggleString",
@ -76,8 +81,8 @@ class AESDecrypt extends Operation {
mode = args[2],
inputType = args[3],
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) {
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
});
decipher.update(forge.util.createBuffer(input));
const result = decipher.finish();
const result = (padding === "No") ? decipher.finish() : decipher.finish(() => true);
console.log(result);
if (result) {
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
} else {

View file

@ -53,6 +53,11 @@ class AESEncrypt extends Operation {
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["No", "Yes"]
}
];
}
@ -70,7 +75,7 @@ class AESEncrypt extends Operation {
mode = args[2],
inputType = args[3],
outputType = args[4];
var padding = args[5];
if ([16, 24, 32].indexOf(key.length) < 0) {
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);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer(input));
cipher.finish();
(padding === "No") ? cipher.finish() : cipher.finish(() => true);
if (outputType === "Hex") {
if (mode === "GCM") {