From 46f92ac829cfaeb255317c99a0cb220e1ff6b071 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 27 Jan 2019 17:48:07 +0100 Subject: Added pin input field(s) --- public/scripts/2_encryption.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'public/scripts/2_encryption.js') diff --git a/public/scripts/2_encryption.js b/public/scripts/2_encryption.js index e33b475..a6f610e 100644 --- a/public/scripts/2_encryption.js +++ b/public/scripts/2_encryption.js @@ -105,8 +105,7 @@ async function encrypt(data, publicKey) { * @returns {Promise} */ async function decrypt(data, publicKey, privateKey, passphrase) { - const privateKeyObj = (await openpgp.key.readArmored(privateKey)).keys[0]; - await privateKeyObj.decrypt(passphrase); + const privateKeyObj = await decryptPrivateKey(privateKey, passphrase); const options = { message: await openpgp.message.readArmored(data), @@ -114,7 +113,19 @@ async function decrypt(data, publicKey, privateKey, passphrase) { privateKeys: [privateKeyObj] }; - return await openpgp.decrypt(options).then(plaintext => plaintext.data) + return await openpgp.decrypt(options).then(plaintext => plaintext.data); +} + +/** + * Decrypts the private key + * @param privateKey + * @param passphrase + * @returns {Promise} + */ +async function decryptPrivateKey(privateKey, passphrase) { + const privateKeyObj = (await openpgp.key.readArmored(privateKey)).keys[0]; + await privateKeyObj.decrypt(passphrase); + return privateKeyObj; } /** @@ -187,9 +198,8 @@ exports.getPrivate = getPrivateKey; exports.getPublic = getPublicKey; exports.encrypt = encrypt; exports.decrypt = decrypt; +exports.decryptPrivate = decryptPrivateKey; exports.check = isEncrypted; exports.store = storePeerPublicKey; exports.get = getPeerPublicKey; exports.test = testEncryption; - -window.pgp = openpgp; -- cgit v1.2.3