mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
Added 'Key Padding' to DES
This commit is contained in:
parent
a811041fe2
commit
99afd014f2
3 changed files with 36 additions and 18 deletions
|
@ -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;
|
||||
const 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
|
||||
|
|
|
@ -619,7 +619,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": ""},
|
||||
"CBC", "Hex", "Hex"
|
||||
"CBC", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -634,7 +634,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"CBC", "Hex", "Hex"
|
||||
"CBC", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -649,7 +649,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"CFB", "Hex", "Hex"
|
||||
"CFB", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -664,7 +664,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"OFB", "Hex", "Hex"
|
||||
"OFB", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -680,7 +680,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"CTR", "Hex", "Hex"
|
||||
"CTR", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -695,7 +695,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"ECB", "Hex", "Hex"
|
||||
"ECB", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1370,7 +1370,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": ""},
|
||||
"CBC", "Hex", "Hex"
|
||||
"CBC", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1385,7 +1385,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"CBC", "Hex", "Hex"
|
||||
"CBC", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1400,7 +1400,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"CFB", "Hex", "Hex"
|
||||
"CFB", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1415,7 +1415,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"OFB", "Hex", "Hex"
|
||||
"OFB", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1431,7 +1431,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"CTR", "Hex", "Hex"
|
||||
"CTR", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1446,7 +1446,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
|||
"args": [
|
||||
{"option": "Hex", "string": "58345efb0a64e87e"},
|
||||
{"option": "Hex", "string": "533ed1378bfd929e"},
|
||||
"ECB", "Hex", "Hex"
|
||||
"ECB", "Hex", "Hex", "None"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue