X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=strappCrypto.js;fp=strappCrypto.js;h=cc6fd75601a07055389fd0511d4d43aa2afce2a6;hp=0000000000000000000000000000000000000000;hb=44e0b2d571c71ebd410b78366c8bc9dc463a96c4;hpb=d17ac76d8256b00eb253138a554c7d3d51139b9e diff --git a/strappCrypto.js b/strappCrypto.js new file mode 100644 index 0000000..cc6fd75 --- /dev/null +++ b/strappCrypto.js @@ -0,0 +1,57 @@ +/** + * @file Management for bootstrapp cryptography + * @desc Makes keys, encrypts and decrypts messages + * + * @author Jordan Lavatai and Ken Grimes + * @version 0.0.1 + * @license AGPL-3.0 + * @copyright Strapp.io + */ + +import {setItem, getItem} from "localForage" + +/** @func Generates a CryptoKey and returns a SHA-256 client key + * @desc Utilizes Web Crypto to create a CryptoKey using RSA specification. + * Stores both public and private representation of the key and returns + * the public key + * @return {String} clientKey + */ +function generateKey() { + crypto.subtle.generateKey( + { name:'RSA-OAEP', + modulusLength: 2048, + publicExponent: new Uint8Array([0x01, 0x00, 0x01]), + hash: {name: "SHA-256"} + }, + true, + ['encrypt', 'decrypt'] + ).then((cryptoKey) => { + /* TODO: Do we need to store the private key as well? */ + crypto.subtle.exportKey('jwk', cryptoKey) + .then((exportedKey) => { + setItem('publicKey', exportedKey.publicKey) + setItem('privateKey', exportedKey.privateKey) + console.log('public key is' + getItem('publicKey')) + console.log('private key is' + getItem('privateKey')) + return exportedKey.publicKey + }) + }) +} + +/** @func Encrypts data with a public key + * @desc + * @arg {String} Public Key + * @return {Object} The encrypted data + */ +function encryptData(publicKey, data) { + +} +/** @func Decrypts data with a private key + * @desc + * @arg {String} Private key to decrypt data + * @return {Object} The decrypted data + */ +function decryptData(privateKey, data) { +} + +function