Refactored into strapp Modules. All in progress with File System current focus
[henge/kiak.git] / strappCrypto.js
1 /**
2 * @file Management for bootstrapp cryptography
3 * @desc Makes keys, encrypts and decrypts messages
4 *
5 * @author Jordan Lavatai and Ken Grimes
6 * @version 0.0.1
7 * @license AGPL-3.0
8 * @copyright Strapp.io
9 */
10
11 import {setItem, getItem} from "localForage"
12
13 /** @func Generates a CryptoKey and returns a SHA-256 client key
14 * @desc Utilizes Web Crypto to create a CryptoKey using RSA specification.
15 * Stores both public and private representation of the key and returns
16 * the public key
17 * @return {String} clientKey
18 */
19 function generateKey() {
20 crypto.subtle.generateKey(
21 { name:'RSA-OAEP',
22 modulusLength: 2048,
23 publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
24 hash: {name: "SHA-256"}
25 },
26 true,
27 ['encrypt', 'decrypt']
28 ).then((cryptoKey) => {
29 /* TODO: Do we need to store the private key as well? */
30 crypto.subtle.exportKey('jwk', cryptoKey)
31 .then((exportedKey) => {
32 setItem('publicKey', exportedKey.publicKey)
33 setItem('privateKey', exportedKey.privateKey)
34 console.log('public key is' + getItem('publicKey'))
35 console.log('private key is' + getItem('privateKey'))
36 return exportedKey.publicKey
37 })
38 })
39 }
40
41 /** @func Encrypts data with a public key
42 * @desc
43 * @arg {String} Public Key
44 * @return {Object} The encrypted data
45 */
46 function encryptData(publicKey, data) {
47
48 }
49 /** @func Decrypts data with a private key
50 * @desc
51 * @arg {String} Private key to decrypt data
52 * @return {Object} The decrypted data
53 */
54 function decryptData(privateKey, data) {
55 }
56
57 function