mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Added passphrase support to importing private key
This commit is contained in:
parent
f07263ca2a
commit
6a67fe09de
2 changed files with 4015 additions and 4000 deletions
|
@ -3974,6 +3974,11 @@ const OperationConfig = {
|
||||||
type: "text",
|
type: "text",
|
||||||
value: ""
|
value: ""
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Passphrase",
|
||||||
|
type: "text",
|
||||||
|
value: ""
|
||||||
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -162,15 +162,25 @@ const PGP = {
|
||||||
|
|
||||||
async runDecrypt(input, args) {
|
async runDecrypt(input, args) {
|
||||||
let encryptedMessage = input,
|
let encryptedMessage = input,
|
||||||
plainPrivateKey = args[0],
|
privateKey = args[0],
|
||||||
|
passphrase = args[1],
|
||||||
keyring = new kbpgp.keyring.KeyRing();
|
keyring = new kbpgp.keyring.KeyRing();
|
||||||
|
|
||||||
let key, plaintextMessage;
|
let key, plaintextMessage;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
||||||
armored: plainPrivateKey,
|
armored: privateKey,
|
||||||
});
|
});
|
||||||
|
if (key.is_pgp_locked() && passphrase) {
|
||||||
|
if (passphrase) {
|
||||||
|
await promisify(key.unlock_pgp, key)({
|
||||||
|
passphrase
|
||||||
|
});
|
||||||
|
} else if (!passphrase) {
|
||||||
|
throw "Did not provide passphrase with locked private key.";
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Could not import private key: ${err}`;
|
throw `Could not import private key: ${err}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue