Added 'Key Padding' to Blowfish

This commit is contained in:
Michael Rowley 2022-03-22 23:03:05 +00:00
parent bdef47dad8
commit 80379e3df1
3 changed files with 66 additions and 26 deletions

View file

@ -54,6 +54,11 @@ class BlowfishDecrypt extends Operation {
"name": "Output",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Key Padding",
"type": "option",
"value": ["None", "Null", "Repeat"]
}
];
}
@ -64,11 +69,16 @@ class BlowfishDecrypt extends Operation {
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
var key = Utils.convertToByteString(args[0].string, args[0].option);
const iv = Utils.convertToByteString(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 < 8) {
key = key.padEnd(8, keyPadding === "Null" ? "\0" : key);
}
if (key.length !== 8) {
throw new OperationError(`Invalid key length: ${key.length} bytes

View file

@ -54,6 +54,11 @@ class BlowfishEncrypt extends Operation {
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Key Padding",
"type": "option",
"value": ["None", "Null", "Repeat"]
}
];
}
@ -64,11 +69,16 @@ class BlowfishEncrypt extends Operation {
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
var key = Utils.convertToByteString(args[0].string, args[0].option);
const iv = Utils.convertToByteString(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 < 8) {
key = key.padEnd(8, keyPadding === "Null" ? "\0" : key);
}
if (key.length !== 8) {
throw new OperationError(`Invalid key length: ${key.length} bytes