From b785f4482a89a8c304fc03449d796ce036a5f85b Mon Sep 17 00:00:00 2001 From: Storms-Engineering Date: Sat, 12 Oct 2019 08:44:39 -0800 Subject: [PATCH] DES Encryption: Check Length of IV Encryption operation now checks the length of the IV. Also changed test to use utf8 instead of HEX because the hex string wasn't valid. --- src/core/lib/Hex.mjs | 2 +- src/core/operations/DESEncrypt.mjs | 7 +++++-- tests/node/tests/operations.mjs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 5ae06a7e..1c9c7eca 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -90,7 +90,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { const delimRegex = delim === "Auto" ? /[^a-f\d]/gi : Utils.regexRep(delim); data = data.replace(delimRegex, ""); } - + const output = []; for (let i = 0; i < data.length; i += byteLen) { output.push(parseInt(data.substr(i, byteLen), 16)); diff --git a/src/core/operations/DESEncrypt.mjs b/src/core/operations/DESEncrypt.mjs index 5ea5f5fc..19ef452e 100644 --- a/src/core/operations/DESEncrypt.mjs +++ b/src/core/operations/DESEncrypt.mjs @@ -19,7 +19,6 @@ class DESEncrypt extends Operation { */ constructor() { super(); - this.name = "DES Encrypt"; this.module = "Ciphers"; this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.

Key: DES uses a key length of 8 bytes (64 bits).
Triple DES uses a key length of 24 bytes (192 bits).

You can generate a password-based key using one of the KDF operations.

IV: The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.

Padding: In CBC and ECB mode, PKCS#7 padding will be used."; @@ -73,9 +72,13 @@ class DESEncrypt extends Operation { DES uses a key length of 8 bytes (64 bits). Triple DES uses a key length of 24 bytes (192 bits).`); } + else if(iv.length !== 8) { + throw new OperationError(`Invalid IV length: ${iv.length} bytes +DES uses a iv length of 8 bytes (64 bits).`); + + } input = Utils.convertToByteString(input, inputType); - const cipher = forge.cipher.createCipher("DES-" + mode, key); cipher.start({iv: iv}); cipher.update(forge.util.createBuffer(input)); diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index 42ba74c9..b8bc2500 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -415,7 +415,7 @@ color: white; }, iv: { string: "threetwo", - option: "Hex", + option: "utf8", }, mode: "ECB", });