mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
Merge 8d7b4a6b7d
into 1400b5cca4
This commit is contained in:
commit
7b190ad142
10 changed files with 504 additions and 135 deletions
|
@ -90,6 +90,11 @@ class AESDecrypt extends Operation {
|
|||
"type": "toggleString",
|
||||
"value": "",
|
||||
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
|
||||
},
|
||||
{
|
||||
"name": "Key Padding",
|
||||
"type": "option",
|
||||
"value": ["None", "Null", "Repeat"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -102,15 +107,30 @@ class AESDecrypt extends Operation {
|
|||
* @throws {OperationError} if cannot decrypt input or invalid key length
|
||||
*/
|
||||
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],
|
||||
gcmTag = Utils.convertToByteString(args[5].string, args[5].option),
|
||||
aad = Utils.convertToByteString(args[6].string, args[6].option);
|
||||
aad = Utils.convertToByteString(args[6].string, args[6].option),
|
||||
keyPadding = args[7],
|
||||
keySizes = [16, 24, 32];
|
||||
|
||||
if ([16, 24, 32].indexOf(key.length) < 0) {
|
||||
if (keyPadding !== "None") {
|
||||
var targetKeySize = 0;
|
||||
for (var i = 0; i < keySizes.length; i++) {
|
||||
if (key.length < keySizes[i]) {
|
||||
targetKeySize = keySizes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetKeySize !== 0) {
|
||||
key = key.padEnd(targetKeySize, keyPadding == "Null" ? "\0" : key);
|
||||
}
|
||||
}
|
||||
|
||||
if (keySizes.indexOf(key.length) < 0) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
The following algorithms will be used based on the size of the key:
|
||||
|
|
|
@ -84,6 +84,11 @@ class AESEncrypt extends Operation {
|
|||
"type": "toggleString",
|
||||
"value": "",
|
||||
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
|
||||
},
|
||||
{
|
||||
"name": "Key Padding",
|
||||
"type": "option",
|
||||
"value": ["None", "Null", "Repeat"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -96,14 +101,29 @@ class AESEncrypt extends Operation {
|
|||
* @throws {OperationError} if invalid key length
|
||||
*/
|
||||
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],
|
||||
aad = Utils.convertToByteString(args[5].string, args[5].option);
|
||||
aad = Utils.convertToByteString(args[5].string, args[5].option),
|
||||
keyPadding = args[6],
|
||||
keySizes = [16, 24, 32];
|
||||
|
||||
if ([16, 24, 32].indexOf(key.length) < 0) {
|
||||
if (keyPadding !== "None") {
|
||||
var targetKeySize = 0;
|
||||
for (var i = 0; i < keySizes.length; i++) {
|
||||
if (key.length < keySizes[i]) {
|
||||
targetKeySize = keySizes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetKeySize !== 0) {
|
||||
key = key.padEnd(targetKeySize, keyPadding === "Null" ? "\0" : key);
|
||||
}
|
||||
}
|
||||
|
||||
if (keySizes.indexOf(key.length) < 0) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
The following algorithms will be used based on the size of the key:
|
||||
|
@ -113,7 +133,6 @@ The following algorithms will be used based on the size of the key:
|
|||
}
|
||||
|
||||
input = Utils.convertToByteString(input, inputType);
|
||||
|
||||
const cipher = forge.cipher.createCipher("AES-" + mode, key);
|
||||
cipher.start({
|
||||
iv: iv,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -53,6 +53,11 @@ class DESDecrypt extends Operation {
|
|||
"name": "Output",
|
||||
"type": "option",
|
||||
"value": ["Raw", "Hex"]
|
||||
},
|
||||
{
|
||||
"name": "Key Padding",
|
||||
"type": "option",
|
||||
"value": ["None", "Null", "Repeat"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -63,9 +68,13 @@ class DESDecrypt 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),
|
||||
[,, mode, inputType, outputType] = args;
|
||||
var key = Utils.convertToByteString(args[0].string, args[0].option);
|
||||
var iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||
[,, mode, inputType, outputType, keyPadding] = args;
|
||||
|
||||
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
|
||||
|
|
|
@ -53,6 +53,11 @@ class DESEncrypt extends Operation {
|
|||
"name": "Output",
|
||||
"type": "option",
|
||||
"value": ["Hex", "Raw"]
|
||||
},
|
||||
{
|
||||
"name": "Key Padding",
|
||||
"type": "option",
|
||||
"value": ["None", "Null", "Repeat"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -63,9 +68,13 @@ class DESEncrypt 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),
|
||||
[,, mode, inputType, outputType] = args;
|
||||
var key = Utils.convertToByteString(args[0].string, args[0].option);
|
||||
const iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||
[,, mode, inputType, outputType, keyPadding] = args;
|
||||
|
||||
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
|
||||
|
|
|
@ -53,6 +53,11 @@ class TripleDESDecrypt extends Operation {
|
|||
"name": "Output",
|
||||
"type": "option",
|
||||
"value": ["Raw", "Hex"]
|
||||
},
|
||||
{
|
||||
"name": "Key Padding",
|
||||
"type": "option",
|
||||
"value": ["None", "Null", "Repeat"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -63,11 +68,16 @@ class TripleDESDecrypt 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
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -67,7 +67,8 @@ TestRegister.addTests([
|
|||
{
|
||||
"option": "Hex",
|
||||
"string": ""
|
||||
}
|
||||
},
|
||||
"None"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue