2 * @file Management for bootstrapp cryptography
3 * @desc Makes keys, encrypts and decrypts messages
5 * @author Jordan Lavatai and Ken Grimes
11 import {setItem
, getItem
} from "localForage"
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
17 * @return {String} clientKey
19 function generateKey() {
20 crypto
.subtle
.generateKey(
23 publicExponent
: new Uint8Array([0x01, 0x00, 0x01]),
24 hash
: {name
: "SHA-256"}
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
41 /** @func Encrypts data with a public key
43 * @arg {String} Public Key
44 * @return {Object} The encrypted data
46 function encryptData(publicKey
, data
) {
49 /** @func Decrypts data with a private key
51 * @arg {String} Private key to decrypt data
52 * @return {Object} The decrypted data
54 function decryptData(privateKey
, data
) {