mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
WIP: add encrypt and decrypt operations
Currently the encrypt operation works only to my public key and not to keys generated by the generate key pair operation. Probably something wrong with the generate operation.
This commit is contained in:
parent
5a5ce1101b
commit
db8955d90d
6 changed files with 1293 additions and 17 deletions
6
.babelrc
6
.babelrc
|
@ -1,4 +1,10 @@
|
||||||
{
|
{
|
||||||
|
"plugins": [
|
||||||
|
["transform-runtime", {
|
||||||
|
"polyfill": false,
|
||||||
|
"regenerator": true
|
||||||
|
}]
|
||||||
|
],
|
||||||
"presets": [
|
"presets": [
|
||||||
["env", {
|
["env", {
|
||||||
"targets": {
|
"targets": {
|
||||||
|
|
1201
package-lock.json
generated
1201
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -32,7 +32,11 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.26.0",
|
"babel-core": "^6.26.0",
|
||||||
"babel-loader": "^7.1.2",
|
"babel-loader": "^7.1.2",
|
||||||
|
"babel-plugin-transform-runtime": "^6.23.0",
|
||||||
|
"babel-polyfill": "^6.26.0",
|
||||||
"babel-preset-env": "^1.6.0",
|
"babel-preset-env": "^1.6.0",
|
||||||
|
"babel-preset-es2015": "^6.24.1",
|
||||||
|
"babel-preset-stage-0": "^6.24.1",
|
||||||
"css-loader": "^0.28.7",
|
"css-loader": "^0.28.7",
|
||||||
"exports-loader": "^0.6.4",
|
"exports-loader": "^0.6.4",
|
||||||
"extract-text-webpack-plugin": "^3.0.1",
|
"extract-text-webpack-plugin": "^3.0.1",
|
||||||
|
@ -67,7 +71,6 @@
|
||||||
"worker-loader": "^1.0.0"
|
"worker-loader": "^1.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-polyfill": "^6.26.0",
|
|
||||||
"bootstrap": "^3.3.7",
|
"bootstrap": "^3.3.7",
|
||||||
"bootstrap-colorpicker": "^2.5.2",
|
"bootstrap-colorpicker": "^2.5.2",
|
||||||
"bootstrap-switch": "^3.3.4",
|
"bootstrap-switch": "^3.3.4",
|
||||||
|
|
|
@ -3880,6 +3880,34 @@ const OperationConfig = {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"PGP Encrypt": {
|
||||||
|
module: "PGP",
|
||||||
|
manualBake: true,
|
||||||
|
description: "",
|
||||||
|
inputType: "string",
|
||||||
|
outputType: "string",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: "Public key",
|
||||||
|
type: "text",
|
||||||
|
value: ""
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"PGP Decrypt": {
|
||||||
|
module: "PGP",
|
||||||
|
manualBake: true,
|
||||||
|
description: "",
|
||||||
|
inputType: "string",
|
||||||
|
outputType: "string",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: "Private key",
|
||||||
|
type: "text",
|
||||||
|
value: ""
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ let OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
|
||||||
|
|
||||||
OpModules.PGP = {
|
OpModules.PGP = {
|
||||||
"Generate PGP Key Pair": PGP.runGenerateKeyPair,
|
"Generate PGP Key Pair": PGP.runGenerateKeyPair,
|
||||||
|
"PGP Encrypt": PGP.runEncrypt,
|
||||||
|
"PGP Decrypt": PGP.runDecrypt,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default OpModules;
|
export default OpModules;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/*eslint camelcase: ["error", {properties: "never"}]*/
|
||||||
import * as kbpgp from "kbpgp";
|
import * as kbpgp from "kbpgp";
|
||||||
import promisify from "es6-promisify";
|
import promisify from "es6-promisify";
|
||||||
|
|
||||||
|
@ -105,16 +106,16 @@ const PGP = {
|
||||||
primary: {
|
primary: {
|
||||||
nbits: keySize,
|
nbits: keySize,
|
||||||
flags: flags,
|
flags: flags,
|
||||||
expire_in: 0 // eslint-disable-line camelcase
|
expire_in: 0
|
||||||
},
|
},
|
||||||
subkeys: [{
|
subkeys: [{
|
||||||
nbits: PGP.getSubkeySize(keySize),
|
nbits: PGP.getSubkeySize(keySize),
|
||||||
flags: kbpgp.const.openpgp.sign_data,
|
flags: kbpgp.const.openpgp.sign_data,
|
||||||
expire_in: 86400 * 365 * 8 // eslint-disable-line camelcase
|
expire_in: 86400 * 365 * 8
|
||||||
}, {
|
}, {
|
||||||
nbits: PGP.getSubkeySize(keySize),
|
nbits: PGP.getSubkeySize(keySize),
|
||||||
flags: kbpgp.const.openpgp.encrypt_comm | kbpgp.const.openpgp.encrypt_storage,
|
flags: kbpgp.const.openpgp.encrypt_comm | kbpgp.const.openpgp.encrypt_storage,
|
||||||
expire_in: 86400 * 365 * 2 // eslint-disable-line camelcase
|
expire_in: 86400 * 365 * 2
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
@ -131,7 +132,66 @@ const PGP = {
|
||||||
reject(`Error from kbpgp whilst generating key pair: ${err}`);
|
reject(`Error from kbpgp whilst generating key pair: ${err}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async runEncrypt(input, args) {
|
||||||
|
let plaintextMessage = input,
|
||||||
|
plainPubKey = args[0];
|
||||||
|
|
||||||
|
let key, encryptedMessage;
|
||||||
|
|
||||||
|
try {
|
||||||
|
key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
||||||
|
armored: plainPubKey,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
throw `Could not import public key: ${err}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
encryptedMessage = await promisify(kbpgp.box)({
|
||||||
|
msg: plaintextMessage,
|
||||||
|
encrypt_for: key,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
throw `Could encrypt message to provided public key: ${err}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(encryptedMessage);
|
||||||
|
|
||||||
|
return encryptedMessage;
|
||||||
|
},
|
||||||
|
|
||||||
|
async runDecrypt(input, args) {
|
||||||
|
let encryptedMessage = input,
|
||||||
|
plainPrivateKey = args[0],
|
||||||
|
keyring = new kbpgp.keyring.KeyRing();
|
||||||
|
|
||||||
|
let key, plaintextMessage;
|
||||||
|
|
||||||
|
try {
|
||||||
|
key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
||||||
|
armored: plainPrivateKey,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
throw `Could not import private key: ${err}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyring.add_key_manager(key);
|
||||||
|
|
||||||
|
try {
|
||||||
|
plaintextMessage = await promisify(kbpgp.unbox)({
|
||||||
|
armored: encryptedMessage,
|
||||||
|
keyfetch: keyring,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
throw `Could decrypt message to provided private key: ${err}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return plaintextMessage;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PGP;
|
export default PGP;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue