mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Added Key Option
This commit is contained in:
parent
903ea45228
commit
3950dba2c5
5 changed files with 62 additions and 22 deletions
|
@ -36,6 +36,11 @@ class BLAKE2b extends Operation {
|
|||
"name": "Output Encoding",
|
||||
"type": "option",
|
||||
"value": ["Hex", "Base64", "Raw"]
|
||||
}, {
|
||||
"name": "Key",
|
||||
"type": "toggleString",
|
||||
"value": "",
|
||||
"toggleValues": ["UTF8", "Decimal", "Base64", "Hex", "Latin1"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -47,14 +52,19 @@ class BLAKE2b extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
const [outSize, outFormat] = args;
|
||||
|
||||
let key = Utils.convertToByteArray(args[2].string || "", args[2].option);
|
||||
if (key.length === 0){
|
||||
key = null;
|
||||
} else if (key.length > 64){
|
||||
throw new OperationError(["Key cannot be greater than 64 bytes", "It is currently " + key.length +" bytes."].join("\n"));
|
||||
}
|
||||
switch (outFormat) {
|
||||
case "Hex":
|
||||
return blakejs.blake2bHex(input, null, outSize / 8);
|
||||
return blakejs.blake2bHex(input, key, outSize / 8);
|
||||
case "Base64":
|
||||
return toBase64(blakejs.blake2b(input, null, outSize / 8));
|
||||
return toBase64(blakejs.blake2b(input, key, outSize / 8));
|
||||
case "Raw":
|
||||
return Utils.arrayBufferToStr(blakejs.blake2b(input, null, outSize / 8).buffer);
|
||||
return Utils.arrayBufferToStr(blakejs.blake2b(input, key, outSize / 8).buffer);
|
||||
default:
|
||||
return new OperationError("Unsupported Output Type");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue