edits
authorBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sat, 23 Jul 2016 08:19:59 +0000 (01:19 -0700)
committerBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sat, 23 Jul 2016 08:19:59 +0000 (01:19 -0700)
src/java/iotcloud/Slot.java
src/java/iotcloud/Table.java

index 8d12fc2..841e818 100644 (file)
@@ -14,10 +14,6 @@ class Slot {
        long machineid;
        Vector<Entry> entries;
 
-       Slot(Vector _entries) {
-               entries=_entries;
-       }
-
        Slot(long _seqnum, long _machineid, byte[] _prevhmac, byte[] _hmac, Vector<Entry> _entries) {
                seqnum=_seqnum;
                machineid=_machineid;
index beceb7c..ad5f69e 100644 (file)
@@ -1,6 +1,43 @@
 package iotcloud;
+import java.util.HashMap;
+import javax.crypto.spec.*;
+import javax.crypto.*;
 
 public class Table {
-       int tablesize;
+       int numslots;
+       HashMap table=new HashMap();
+       CloudComm cloud;
+       private Cipher encryptCipher;
+       private Cipher decryptCipher;
+       private Mac hmac;
        
+       public Table(String baseurl, String password) {
+               cloud=new CloudComm(baseurl);
+               initCiphers(password);
+       }
+       
+       private void initCiphers(String password) {
+               try {
+                       SecretKeySpec secret=getKey(password);
+                       encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+                       encryptCipher.init(Cipher.ENCRYPT_MODE, secret);
+                       decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+                       decryptCipher.init(Cipher.DECRYPT_MODE, secret);
+                       hmac = Mac.getInstance("HmacSHA256");
+                       hmac.init(secret);
+               } catch (Exception e) {
+                       throw new Error("Failed To Initialize Ciphers");
+               }
+       }
+
+       private SecretKeySpec getKey(String password) {
+               try {
+                       PBEKeySpec keyspec = new PBEKeySpec(password.toCharArray());
+                       SecretKey key = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(keyspec);
+                       SecretKeySpec secret = new SecretKeySpec(key.getEncoded(), "AES");
+                       return secret;
+               } catch (Exception e) {
+                       throw new Error("Failed generating key.");
+               }
+       }
 }