Use byteArray for I/O of cipher operations

This commit is contained in:
MikeCAT 2025-02-19 18:03:31 +00:00
parent 1b8c229df2
commit 6272d0e809
14 changed files with 104 additions and 85 deletions

View file

@ -24,8 +24,8 @@ class TripleDESDecrypt extends Operation {
this.module = "Ciphers";
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
this.infoURL = "https://wikipedia.org/wiki/Triple_DES";
this.inputType = "string";
this.outputType = "string";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.args = [
{
"name": "Key",
@ -58,9 +58,9 @@ class TripleDESDecrypt extends Operation {
}
/**
* @param {string} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
* @returns {byteArray}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
@ -82,6 +82,7 @@ Triple DES uses an IV length of 8 bytes (64 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
}
input = input.map((c) => String.fromCharCode(c)).join("");
input = Utils.convertToByteString(input, inputType);
const decipher = forge.cipher.createDecipher("3DES-" + mode,
@ -99,7 +100,8 @@ Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
const result = decipher.finish();
if (result) {
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
const output = outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
return Array.from(output).map((c) => c.charCodeAt(0));
} else {
throw new OperationError("Unable to decrypt input with these parameters.");
}