mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26: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");
|
||||
}
|
||||
|
|
|
@ -35,6 +35,12 @@ class BLAKE2s extends Operation {
|
|||
"name": "Output Encoding",
|
||||
"type": "option",
|
||||
"value": ["Hex", "Base64", "Raw"]
|
||||
},
|
||||
{
|
||||
"name": "Key",
|
||||
"type": "toggleString",
|
||||
"value": "",
|
||||
"toggleValues": ["UTF8", "Decimal", "Base64", "Hex", "Latin1"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -46,13 +52,19 @@ class BLAKE2s 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 > 32){
|
||||
throw new OperationError(["Key cannot be greater than 32 bytes", "It is currently " + key.length +" bytes."].join("\n"));
|
||||
}
|
||||
switch (outFormat) {
|
||||
case "Hex":
|
||||
return blakejs.blake2sHex(input, null, outSize / 8);
|
||||
return blakejs.blake2sHex(input, key, outSize / 8);
|
||||
case "Base64":
|
||||
return toBase64(blakejs.blake2s(input, null, outSize / 8));
|
||||
return toBase64(blakejs.blake2s(input, key, outSize / 8));
|
||||
case "Raw":
|
||||
return Utils.arrayBufferToStr(blakejs.blake2s(input, null, outSize / 8).buffer);
|
||||
return Utils.arrayBufferToStr(blakejs.blake2s(input, key, outSize / 8).buffer);
|
||||
default:
|
||||
return new OperationError("Unsupported Output Type");
|
||||
}
|
||||
|
|
|
@ -90,14 +90,14 @@ class GenerateAllHashes extends Operation {
|
|||
"\nWhirlpool: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool"]) +
|
||||
"\nSSDEEP: " + (new SSDEEP()).run(str) +
|
||||
"\nCTPH: " + (new CTPH()).run(str) +
|
||||
"\nBLAKE2b-512: " + (new BLAKE2b).run(str, ["512", "Hex"]) +
|
||||
"\nBLAKE2b-384: " + (new BLAKE2b).run(str, ["384", "Hex"]) +
|
||||
"\nBLAKE2b-256: " + (new BLAKE2b).run(str, ["256", "Hex"]) +
|
||||
"\nBLAKE2b-160: " + (new BLAKE2b).run(str, ["160", "Hex"]) +
|
||||
"\nBLAKE2b-128: " + (new BLAKE2b).run(str, ["128", "Hex"]) +
|
||||
"\nBLAKE2s-256: " + (new BLAKE2s).run(str, ["256", "Hex"]) +
|
||||
"\nBLAKE2s-160: " + (new BLAKE2s).run(str, ["160", "Hex"]) +
|
||||
"\nBLAKE2s-128: " + (new BLAKE2s).run(str, ["128", "Hex"]) +
|
||||
"\nBLAKE2b-512: " + (new BLAKE2b).run(str, ["512", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-384: " + (new BLAKE2b).run(str, ["384", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-256: " + (new BLAKE2b).run(str, ["256", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-160: " + (new BLAKE2b).run(str, ["160", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-128: " + (new BLAKE2b).run(str, ["128", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2s-256: " + (new BLAKE2s).run(str, ["256", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2s-160: " + (new BLAKE2s).run(str, ["160", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2s-128: " + (new BLAKE2s).run(str, ["128", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\n\nChecksums:" +
|
||||
"\nFletcher-8: " + (new Fletcher8Checksum).run(byteArray, []) +
|
||||
"\nFletcher-16: " + (new Fletcher16Checksum).run(byteArray, []) +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue