Add Fernet encrypt/decrypt

This commit is contained in:
Karsten Silkenbäumer 2018-10-29 21:48:45 +01:00
parent 21ea4b9c0e
commit dcee118f4a
5 changed files with 134 additions and 0 deletions

23
package-lock.json generated
View File

@ -4725,11 +4725,29 @@
"pend": "~1.2.0"
}
},
<<<<<<< HEAD
"figgy-pudding": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz",
"integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==",
"dev": true
=======
"fernet": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/fernet/-/fernet-0.3.1.tgz",
"integrity": "sha512-7KnsrcpLkUsKy6aH6Ow68hrMWhvE25rTDd3370+xVGkpqZta05cUCmdJQPyLBKTsNdPUB5NumJZBgJIJ60aQqw==",
"requires": {
"crypto-js": "~3.1.2-1",
"urlsafe-base64": "1.0.0"
},
"dependencies": {
"crypto-js": {
"version": "3.1.8",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.8.tgz",
"integrity": "sha1-cV8HC/YBTyrpkqmLOSkli3E/CNU="
}
}
>>>>>>> Add Fernet encrypt/decrypt
},
"figures": {
"version": "2.0.0",
@ -12952,6 +12970,11 @@
"requires-port": "^1.0.0"
}
},
"urlsafe-base64": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/urlsafe-base64/-/urlsafe-base64-1.0.0.tgz",
"integrity": "sha1-I/iQaabGL0bPOh07ABac77kL4MY="
},
"use": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",

View File

@ -97,6 +97,7 @@
"esmangle": "^1.0.1",
"esprima": "^4.0.1",
"exif-parser": "^0.1.12",
"fernet": "^0.3.1",
"file-saver": "^2.0.0",
"geodesy": "^1.1.3",
"highlight.js": "^9.13.1",

View File

@ -73,6 +73,8 @@
"DES Decrypt",
"Triple DES Encrypt",
"Triple DES Decrypt",
"Fernet Encrypt",
"Fernet Decrypt",
"RC2 Encrypt",
"RC2 Decrypt",
"RC4",

View File

@ -0,0 +1,58 @@
/**
* @author kassi [kassi@noreply.com]
* @copyright KS 2018
* @license Apache-2.0
*/
import Operation from '../Operation';
/**
* 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().';
this.infoURL = 'https://asecuritysite.com/encryption/fer';
this.inputType = 'string';
this.outputType = 'string';
this.args = [
{
'name': 'Secret',
'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;
var fernet = require('fernet');
var secret = new fernet.Secret(secretInput);
var token = new fernet.Token({
secret: secret,
token: input
})
return token.decode();
}
}
export default FernetDecrypt;

View File

@ -0,0 +1,50 @@
/**
* @author kassi [kassi@noreply.com]
* @copyright KS 2018
* @license Apache-2.0
*/
import Operation from '../Operation';
/**
* 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().';
this.infoURL = 'https://asecuritysite.com/encryption/fer';
this.inputType = 'string';
this.outputType = 'string';
this.args = [
{
'name': 'Secret',
'type': 'string',
'value': ""
},
];
}
/**
* @param {String} input
* @param {Object[]} args
* @returns {String}
*/
run(input, args) {
const [secretInput] = args;
var fernet = require('fernet');
var secret = new fernet.Secret(secretInput);
var token = new fernet.Token({
secret: secret,
})
return token.encode(input);
}
}
export default FernetEncrypt;