From cc3512745905434c3e597563456fe12fcb79d077 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Tue, 7 Apr 2020 12:57:32 +0100 Subject: [PATCH] AAD for AES Added --- src/core/operations/AESEncrypt.mjs | 41 +++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 7375e308..f1ad14cd 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -41,8 +41,33 @@ class AESEncrypt extends Operation { }, { "name": "Mode", - "type": "option", - "value": ["CBC", "CFB", "OFB", "CTR", "GCM", "ECB"] + "type": "argSelector", + "value": [ + { + name: "CBC", + off: [5] + }, + { + name: "CFB", + off: [5] + }, + { + name: "OFB", + off: [5] + }, + { + name:"CTR", + off: [5] + }, + { + name: "GCM", + on: [5] + }, + { + name: "ECB", + off: [5] + } + ] }, { "name": "Input", @@ -53,6 +78,11 @@ class AESEncrypt extends Operation { "name": "Output", "type": "option", "value": ["Hex", "Raw"] + }, + { + "name": "Additional Authenticated Data", + "type": "string", + "value": "" } ]; } @@ -83,7 +113,12 @@ The following algorithms will be used based on the size of the key: input = Utils.convertToByteString(input, inputType); const cipher = forge.cipher.createCipher("AES-" + mode, key); - cipher.start({iv: iv}); + + if (args[5]) + cipher.start({iv: iv, additionalData: args[5]}); + else + cipher.start({iv: iv}); + cipher.update(forge.util.createBuffer(input)); cipher.finish();