diff options
Diffstat (limited to 'public')
-rw-r--r-- | public/scripts/chat.js | 2 | ||||
-rw-r--r-- | public/scripts/encryption.js | 11 |
2 files changed, 7 insertions, 6 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index 36cfdf1..42e6a29 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -131,7 +131,7 @@ function chat() { console.log(`[LOG] Sending message '${message}' to ${connectedPeer.peer}`); connectedPeer.send({ type: 'text', - data: await encryption.encrypt(message, await encryption.get(connectedPeer.peer)) + data: await encryption.encrypt(message, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase) }); await receivedMessage(message, true); } diff --git a/public/scripts/encryption.js b/public/scripts/encryption.js index edbf11d..669f9d4 100644 --- a/public/scripts/encryption.js +++ b/public/scripts/encryption.js @@ -80,16 +80,17 @@ async function getPublicKey() { * Encrypts the data with a public key (e.g the one of the peer with which you're chatting) * @param data * @param publicKey + * @param privateKey + * @param passphrase * @returns {Promise<String>} */ -async function encrypt(data, publicKey) { - //const privateKeyObj = (await openpgp.key.readArmored(privateKey)).keys[0]; - //await privateKeyObj.decrypt(passphrase); +async function encrypt(data, publicKey, privateKey, passphrase) { + const privateKeyObj = await decryptPrivateKey(privateKey, passphrase); const options = { message: openpgp.message.fromText(data), publicKeys: (await openpgp.key.readArmored(publicKey)).keys, - //privateKeys: [privateKeyObj] // TODO: Use private key for signing + privateKeys: [privateKeyObj] // for signing }; return await openpgp.encrypt(options).then(ciphertext => ciphertext.data); @@ -154,7 +155,7 @@ async function storeMessage(peerId, message) { } /** - * Gets a message + * Gets a message // TODO: Fix getting messages * @param peerId * @param publicKey * @param privateKey |