Added passphrase support to importing private key

This commit is contained in:
Matt C 2018-01-12 12:03:46 +00:00
parent f07263ca2a
commit 6a67fe09de
2 changed files with 4015 additions and 4000 deletions

File diff suppressed because it is too large Load Diff

View File

@ -162,15 +162,25 @@ const PGP = {
async runDecrypt(input, args) {
let encryptedMessage = input,
plainPrivateKey = args[0],
privateKey = args[0],
passphrase = args[1],
keyring = new kbpgp.keyring.KeyRing();
let key, plaintextMessage;
try {
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) {
throw `Could not import private key: ${err}`;
}