diff --git a/src/core/operations/TripleDESDecrypt.mjs b/src/core/operations/TripleDESDecrypt.mjs index 7626eeab..8487509f 100644 --- a/src/core/operations/TripleDESDecrypt.mjs +++ b/src/core/operations/TripleDESDecrypt.mjs @@ -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) { diff --git a/src/core/operations/TripleDESEncrypt.mjs b/src/core/operations/TripleDESEncrypt.mjs index 237020a2..720d155d 100644 --- a/src/core/operations/TripleDESEncrypt.mjs +++ b/src/core/operations/TripleDESEncrypt.mjs @@ -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();