mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-24 00:36:16 -04:00
Add fernet encryption/decryption operation
This commit is contained in:
parent
8148c1a8a8
commit
846e84d3a4
6 changed files with 292 additions and 70 deletions
|
@ -73,6 +73,8 @@
|
|||
"DES Decrypt",
|
||||
"Triple DES Encrypt",
|
||||
"Triple DES Decrypt",
|
||||
"Fernet Encrypt",
|
||||
"Fernet Decrypt",
|
||||
"RC2 Encrypt",
|
||||
"RC2 Decrypt",
|
||||
"RC4",
|
||||
|
|
64
src/core/operations/FernetDecrypt.mjs
Normal file
64
src/core/operations/FernetDecrypt.mjs
Normal file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* @author Karsten Silkenbäumer [kassi@users.noreply.github.com]
|
||||
* @copyright Karsten Silkenbäumer 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import fernet from "fernet";
|
||||
|
||||
/**
|
||||
* FernetDecrypt operation
|
||||
*/
|
||||
class FernetDecrypt extends Operation {
|
||||
/**
|
||||
* FernetDecrypt constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Fernet Decrypt";
|
||||
this.module = "Default";
|
||||
this.description = "Fernet is a symmetric encryption method which makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL safe encoding for the keys. Fernet uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os.random().<br><br><b>Key:</b> The key must be 32 bytes (256 bits) encoded with Base64.";
|
||||
this.infoURL = "https://asecuritysite.com/encryption/fer";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Key",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
];
|
||||
this.patterns = [
|
||||
{
|
||||
match: "^[A-Z\\d\\-_=]{20,}$",
|
||||
flags: "i",
|
||||
args: []
|
||||
},
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @param {String} input
|
||||
* @param {Object[]} args
|
||||
* @returns {String}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [secretInput] = args;
|
||||
// const fernet = require("fernet");
|
||||
try {
|
||||
const secret = new fernet.Secret(secretInput);
|
||||
const token = new fernet.Token({
|
||||
secret: secret,
|
||||
token: input,
|
||||
ttl: 0
|
||||
});
|
||||
return token.decode();
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default FernetDecrypt;
|
54
src/core/operations/FernetEncrypt.mjs
Normal file
54
src/core/operations/FernetEncrypt.mjs
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @author Karsten Silkenbäumer [kassi@users.noreply.github.com]
|
||||
* @copyright Karsten Silkenbäumer 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import fernet from "fernet";
|
||||
|
||||
/**
|
||||
* FernetEncrypt operation
|
||||
*/
|
||||
class FernetEncrypt extends Operation {
|
||||
/**
|
||||
* FernetEncrypt constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Fernet Encrypt";
|
||||
this.module = "Default";
|
||||
this.description = "Fernet is a symmetric encryption method which makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL safe encoding for the keys. Fernet uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os.random().<br><br><b>Key:</b> The key must be 32 bytes (256 bits) encoded with Base64.";
|
||||
this.infoURL = "https://asecuritysite.com/encryption/fer";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Key",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @param {String} input
|
||||
* @param {Object[]} args
|
||||
* @returns {String}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [secretInput] = args;
|
||||
try {
|
||||
const secret = new fernet.Secret(secretInput);
|
||||
const token = new fernet.Token({
|
||||
secret: secret,
|
||||
});
|
||||
return token.encode(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default FernetEncrypt;
|
Loading…
Add table
Add a link
Reference in a new issue