Refactored into strapp Modules. All in progress with File System current focus
[henge/kiak.git] / strappCrypto.js
diff --git a/strappCrypto.js b/strappCrypto.js
new file mode 100644 (file)
index 0000000..cc6fd75
--- /dev/null
@@ -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