mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
Added Output Encoding Option
This commit is contained in:
parent
908043fb7f
commit
b116b8ba1e
4 changed files with 48 additions and 16 deletions
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import blakejs from "blakejs";
|
import blakejs from "blakejs";
|
||||||
|
import OperationError from "../errors/OperationError";
|
||||||
|
import Utils from "../Utils";
|
||||||
|
import { toBase64 } from "../lib/Base64";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BLAKE2b operation
|
* BLAKE2b operation
|
||||||
|
@ -29,6 +32,10 @@ class BLAKE2b extends Operation {
|
||||||
"name": "Size",
|
"name": "Size",
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["512", "384", "256", "160", "128"]
|
"value": ["512", "384", "256", "160", "128"]
|
||||||
|
}, {
|
||||||
|
"name": "Output Encoding",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Hex", "Base64", "Raw"]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -36,11 +43,21 @@ class BLAKE2b extends Operation {
|
||||||
/**
|
/**
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string} The input having been hashed with BLAKE2b, HEX encoded.
|
* @returns {string} The input having been hashed with BLAKE2b in the encoding format speicifed.
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [outSize] = args;
|
const [outSize, outFormat] = args;
|
||||||
return blakejs.blake2bHex(input, null, outSize / 8);
|
|
||||||
|
switch (outFormat) {
|
||||||
|
case "Hex":
|
||||||
|
return blakejs.blake2bHex(input, null, outSize / 8);
|
||||||
|
case "Base64":
|
||||||
|
return toBase64(blakejs.blake2b(input, null, outSize / 8));
|
||||||
|
case "Raw":
|
||||||
|
return Utils.arrayBufferToStr(blakejs.blake2b(input, null, outSize / 8).buffer);
|
||||||
|
default:
|
||||||
|
return new OperationError("Unsupported Output Type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import blakejs from "blakejs";
|
import blakejs from "blakejs";
|
||||||
|
import OperationError from "../errors/OperationError";
|
||||||
|
import Utils from "../Utils";
|
||||||
|
import { toBase64 } from "../lib/Base64";
|
||||||
/**
|
/**
|
||||||
* BLAKE2s Operation
|
* BLAKE2s Operation
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +31,10 @@ class BLAKE2s extends Operation {
|
||||||
"name": "Size",
|
"name": "Size",
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["256", "160", "128"]
|
"value": ["256", "160", "128"]
|
||||||
|
}, {
|
||||||
|
"name": "Output Encoding",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Hex", "Base64", "Raw"]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -36,11 +42,20 @@ class BLAKE2s extends Operation {
|
||||||
/**
|
/**
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string} The input having been hashed with BLAKE2s, HEX encoded.
|
* @returns {string} The input having been hashed with BLAKE2s in the encoding format speicifed.
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [outSize] = args;
|
const [outSize, outFormat] = args;
|
||||||
return blakejs.blake2sHex(input, null, outSize / 8);
|
switch (outFormat) {
|
||||||
|
case "Hex":
|
||||||
|
return blakejs.blake2sHex(input, null, outSize / 8);
|
||||||
|
case "Base64":
|
||||||
|
return toBase64(blakejs.blake2s(input, null, outSize / 8));
|
||||||
|
case "Raw":
|
||||||
|
return Utils.arrayBufferToStr(blakejs.blake2s(input, null, outSize / 8).buffer);
|
||||||
|
default:
|
||||||
|
return new OperationError("Unsupported Output Type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* BitwiseOp tests
|
* BitwiseOp tests
|
||||||
*
|
*
|
||||||
* @author h345983745
|
* @author h345983745
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2019
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
import TestRegister from "../TestRegister";
|
import TestRegister from "../TestRegister";
|
||||||
|
@ -14,7 +14,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "4386a08a265111c9896f56456e2cb61a64239115c4784cf438e36cc851221972da3fb0115f73cd02486254001f878ab1fd126aac69844ef1c1ca152379d0a9bd",
|
expectedOutput: "4386a08a265111c9896f56456e2cb61a64239115c4784cf438e36cc851221972da3fb0115f73cd02486254001f878ab1fd126aac69844ef1c1ca152379d0a9bd",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2b",
|
{ "op": "BLAKE2b",
|
||||||
"args": ["512"] }
|
"args": ["512", "Hex"] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "4d388e82ca8f866e606b6f6f0be910abd62ad6e98c0adfc27cf35acf948986d5c5b9c18b6f47261e1e679eb98edf8e2d",
|
expectedOutput: "4d388e82ca8f866e606b6f6f0be910abd62ad6e98c0adfc27cf35acf948986d5c5b9c18b6f47261e1e679eb98edf8e2d",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2b",
|
{ "op": "BLAKE2b",
|
||||||
"args": ["384"] }
|
"args": ["384", "Hex"] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "1dc01772ee0171f5f614c673e3c7fa1107a8cf727bdf5a6dadb379e93c0d1d00",
|
expectedOutput: "1dc01772ee0171f5f614c673e3c7fa1107a8cf727bdf5a6dadb379e93c0d1d00",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2b",
|
{ "op": "BLAKE2b",
|
||||||
"args": ["256"] }
|
"args": ["256", "Hex"] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "6a8489e6fd6e51fae12ab271ec7fc8134dd5d737",
|
expectedOutput: "6a8489e6fd6e51fae12ab271ec7fc8134dd5d737",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2b",
|
{ "op": "BLAKE2b",
|
||||||
"args": ["160"] }
|
"args": ["160", "Hex"] }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* BitwiseOp tests
|
* BitwiseOp tests
|
||||||
*
|
*
|
||||||
* @author h345983745
|
* @author h345983745
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2019
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
import TestRegister from "../TestRegister";
|
import TestRegister from "../TestRegister";
|
||||||
|
@ -14,7 +14,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "7706af019148849e516f95ba630307a2018bb7bf03803eca5ed7ed2c3c013513",
|
expectedOutput: "7706af019148849e516f95ba630307a2018bb7bf03803eca5ed7ed2c3c013513",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2s",
|
{ "op": "BLAKE2s",
|
||||||
"args": ["256"] }
|
"args": ["256", "Hex"] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "0e4fcfc2ee0097ac1d72d70b595a39e09a3c7c7e",
|
expectedOutput: "0e4fcfc2ee0097ac1d72d70b595a39e09a3c7c7e",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2s",
|
{ "op": "BLAKE2s",
|
||||||
"args": ["160"] }
|
"args": ["160", "Hex"] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ TestRegister.addTests([
|
||||||
expectedOutput: "9964ee6f36126626bf864363edfa96f6",
|
expectedOutput: "9964ee6f36126626bf864363edfa96f6",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{ "op": "BLAKE2s",
|
{ "op": "BLAKE2s",
|
||||||
"args": ["128"] }
|
"args": ["128", "Hex"] }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue