Merge branch 'triple-des-with-16byte-key' of https://github.com/mikecat/CyberChef

This commit is contained in:
n1474335 2022-11-25 12:08:58 +00:00
commit b979b051cb
2 changed files with 6 additions and 4 deletions

View file

@ -70,7 +70,7 @@ class TripleDESDecrypt extends Operation {
inputType = args[3],
outputType = args[4];
if (key.length !== 24) {
if (key.length !== 24 && key.length !== 16) {
throw new OperationError(`Invalid key length: ${key.length} bytes
Triple DES uses a key length of 24 bytes (192 bits).
@ -85,7 +85,8 @@ Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteString(input, inputType);
const decipher = forge.cipher.createDecipher("3DES-" + mode, key);
const decipher = forge.cipher.createDecipher("3DES-" + mode,
key.length === 16 ? key + key.substring(0, 8) : key);
/* Allow for a "no padding" mode */
if (noPadding) {

View file

@ -69,7 +69,7 @@ class TripleDESEncrypt extends Operation {
inputType = args[3],
outputType = args[4];
if (key.length !== 24) {
if (key.length !== 24 && key.length !== 16) {
throw new OperationError(`Invalid key length: ${key.length} bytes
Triple DES uses a key length of 24 bytes (192 bits).
@ -84,7 +84,8 @@ Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteString(input, inputType);
const cipher = forge.cipher.createCipher("3DES-" + mode, key);
const cipher = forge.cipher.createCipher("3DES-" + mode,
key.length === 16 ? key + key.substring(0, 8) : key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer(input));
cipher.finish();