From 9c3e20138d730c167e1869843ec060c7310d8c63 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 24 Jan 2019 15:41:51 +0100 Subject: Added basic key transfer --- public/scripts/2_encryption.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 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 9140a3a..98bd49d 100644 --- a/public/scripts/2_encryption.js +++ b/public/scripts/2_encryption.js @@ -5,13 +5,13 @@ let encrypted, decrypted; // REMEMBER: Remove testing variables (leaking) /** * Generates and stores encrypted private key, public key and a revocation certificate - * @param userId + * @param peerId * @param passphrase * @returns {Promise} */ -async function generateKeys(userId, passphrase) { +async function generateKeys(peerId, passphrase) { const options = { - userIds: [{name: userId}], + peerIds: [{name: peerId}], numBits: 4096, passphrase: passphrase }; @@ -25,7 +25,23 @@ async function generateKeys(userId, passphrase) { } /** - * Encrypts the data with a public key (e.g the one of the person with which you're chatting) + * Gets the peers private key + * @returns {string} + */ +function getPrivateKey() { + return localStorage.getItem('private_key'); +} + +/** + * Gets the peers public key + * @returns {string} + */ +function getPublicKey() { + return localStorage.getItem('public_key'); +} + +/** + * Encrypts the data with a public key (e.g the one of the peer with which you're chatting) * @param data * @param publicKey * @returns {Promise} @@ -73,7 +89,7 @@ async function decrypt(data, publicKey, privateKey, passphrase) { } /** - * Checks whether the user has keys + * Checks whether the peer has keys * @returns {boolean} */ function isEncrypted() { @@ -83,6 +99,16 @@ function isEncrypted() { return (hasPrivateKey && hasPublicKey && hasRevocationCertificate); } +/** + * Stores the public key of a peer + * @param peerId + * @param key + */ +function storePublicKey(peerId, key) { + localStorage.setItem(peerId, key); + console.log('[LOG] Stored public key of ' + peerId); +} + /** * Just a general test case */ @@ -98,7 +124,10 @@ function testEncryption() { } exports.generate = generateKeys; +exports.getPrivate = getPrivateKey; +exports.getPublic = getPublicKey; exports.encrypt = encrypt; exports.decrypt = decrypt; exports.check = isEncrypted; +exports.store = storePublicKey; exports.test = testEncryption; -- cgit v1.2.3