Added 'Key Padding' to Triple DES

This commit is contained in:
Michael Rowley 2022-03-23 15:43:38 +00:00
parent 82da498c24
commit 8d7b4a6b7d
3 changed files with 98 additions and 18 deletions

View file

@ -53,6 +53,11 @@ class TripleDESEncrypt extends Operation {
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Key Padding",
"type": "option",
"value": ["None", "Null", "Repeat"]
}
];
}
@ -63,11 +68,16 @@ class TripleDESEncrypt extends Operation {
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
var key = Utils.convertToByteString(args[0].string, args[0].option);
const iv = Utils.convertToByteArray(args[1].string, args[1].option),
mode = args[2],
inputType = args[3],
outputType = args[4];
outputType = args[4],
keyPadding = args[5];
if (keyPadding !== "None" && key.length < 24) {
key = key.padEnd(24, keyPadding === "Null" ? "\0" : key);
}
if (key.length !== 24) {
throw new OperationError(`Invalid key length: ${key.length} bytes