Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES encrypt/decrypt padding option #867

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/core/operations/AESDecrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand All @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/core/operations/AESEncrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class AESEncrypt extends Operation {
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["No", "Yes"]
}
];
}
Expand All @@ -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

Expand All @@ -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") {
Expand Down