Skip to content

Commit

Permalink
Merge branch 'triple-des-with-16byte-key' of https://github.com/mikec…
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Nov 25, 2022
2 parents 17cf154 + 2255c5b commit b979b05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/core/operations/TripleDESDecrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/core/operations/TripleDESEncrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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();
Expand Down

0 comments on commit b979b05

Please sign in to comment.