From 7a7afebbd927442d387092f0462347913941caba Mon Sep 17 00:00:00 2001 From: Storms-Engineering Date: Thu, 31 Oct 2019 08:38:20 -0800 Subject: [PATCH] Added padding option to AESencrypt/decrypt Added new padding option to AESencryption/decryption that asks if they want padding or not. --- src/core/operations/AESDecrypt.mjs | 13 +++++++++---- src/core/operations/AESEncrypt.mjs | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index 8fe0b93c..99694ad1 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -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 { diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 7375e308..8e43229e 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -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") {