From 663f7480ad9e7e40a43c460ec90664270a3ce748 Mon Sep 17 00:00:00 2001 From: r4mos Date: Thu, 25 Sep 2025 13:13:33 +0200 Subject: [PATCH] Add effective key bits option with 128 by default to RC2 operation --- src/core/operations/RC2Decrypt.mjs | 12 +++++++++--- src/core/operations/RC2Encrypt.mjs | 13 +++++++++---- tests/operations/tests/Crypt.mjs | 6 ++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/core/operations/RC2Decrypt.mjs b/src/core/operations/RC2Decrypt.mjs index c9ff1bf4..7e35f22a 100644 --- a/src/core/operations/RC2Decrypt.mjs +++ b/src/core/operations/RC2Decrypt.mjs @@ -32,6 +32,11 @@ class RC2Decrypt extends Operation { "value": "", "toggleValues": ["Hex", "UTF8", "Latin1", "Base64"] }, + { + name: "Effective key bits", + type: "number", + value: 128 + }, { "name": "IV", "type": "toggleString", @@ -58,9 +63,10 @@ class RC2Decrypt extends Operation { */ run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteString(args[1].string, args[1].option), - [,, inputType, outputType] = args, - decipher = forge.rc2.createDecryptionCipher(key); + effective = args[1], + iv = Utils.convertToByteString(args[2].string, args[2].option), + [,,, inputType, outputType] = args, + decipher = forge.rc2.createDecryptionCipher(key, effective); input = Utils.convertToByteString(input, inputType); diff --git a/src/core/operations/RC2Encrypt.mjs b/src/core/operations/RC2Encrypt.mjs index 88dae5b1..add1555f 100644 --- a/src/core/operations/RC2Encrypt.mjs +++ b/src/core/operations/RC2Encrypt.mjs @@ -8,7 +8,6 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import forge from "node-forge"; - /** * RC2 Encrypt operation */ @@ -33,6 +32,11 @@ class RC2Encrypt extends Operation { "value": "", "toggleValues": ["Hex", "UTF8", "Latin1", "Base64"] }, + { + name: "Effective key bits", + type: "number", + value: 128 + }, { "name": "IV", "type": "toggleString", @@ -59,9 +63,10 @@ class RC2Encrypt extends Operation { */ run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteString(args[1].string, args[1].option), - [,, inputType, outputType] = args, - cipher = forge.rc2.createEncryptionCipher(key); + effective = args[1], + iv = Utils.convertToByteString(args[2].string, args[2].option), + [,,, inputType, outputType] = args, + cipher = forge.rc2.createEncryptionCipher(key, effective); input = Utils.convertToByteString(input, inputType); diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index 504f64b9..893f58ab 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -1488,6 +1488,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "op": "RC2 Encrypt", "args": [ {"option": "Hex", "string": ""}, + 128, {"option": "Hex", "string": ""}, "Hex", "Hex" ] @@ -1503,6 +1504,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "op": "RC2 Encrypt", "args": [ {"option": "Hex", "string": "eb970554bb213430f4bb4e5988a6a218"}, + 128, {"option": "Hex", "string": "ae817c784a097e0c"}, "Hex", "Hex" ] @@ -1518,6 +1520,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "op": "RC2 Encrypt", "args": [ {"option": "Hex", "string": "eb970554bb213430f4bb4e5988a6a218"}, + 128, {"option": "Hex", "string": ""}, "Hex", "Hex" ] @@ -1533,6 +1536,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "op": "RC2 Decrypt", "args": [ {"option": "Hex", "string": ""}, + 128, {"option": "Hex", "string": ""}, "Hex", "Hex" ] @@ -1548,6 +1552,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "op": "RC2 Decrypt", "args": [ {"option": "Hex", "string": "eb970554bb213430f4bb4e5988a6a218"}, + 128, {"option": "Hex", "string": "ae817c784a097e0c"}, "Hex", "Hex" ] @@ -1563,6 +1568,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "op": "RC2 Decrypt", "args": [ {"option": "Hex", "string": "eb970554bb213430f4bb4e5988a6a218"}, + 128, {"option": "Hex", "string": ""}, "Hex", "Hex" ]