edits
authorBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sat, 23 Jul 2016 09:09:52 +0000 (02:09 -0700)
committerBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sat, 23 Jul 2016 09:09:52 +0000 (02:09 -0700)
src/java/iotcloud/CloudComm.java
src/java/iotcloud/Table.java

index 18f7f30..4bc223b 100644 (file)
@@ -2,11 +2,17 @@ package iotcloud;
 import java.io.*;
 import java.net.*;
 import java.util.Arrays;
+import javax.crypto.*;
 
 class CloudComm {
        String baseurl;
-       CloudComm(String _baseurl) {
+       Cipher encryptcipher;
+       Cipher decryptcipher;
+       
+       CloudComm(String _baseurl, Cipher _encrypt, Cipher _decrypt) {
                this.baseurl=_baseurl;
+               this.encryptcipher = _encrypt;
+               this.decryptcipher = _decrypt;
        }
        
        private URL buildRequest(boolean isput, long sequencenumber, long maxentries) throws IOException {
index ad5f69e..f1087ae 100644 (file)
@@ -7,24 +7,22 @@ public class Table {
        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);
+               initCloud(baseurl, password);
        }
-       
-       private void initCiphers(String password) {
+
+       private void initCloud(String baseurl, String password) {
                try {
                        SecretKeySpec secret=getKey(password);
-                       encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+                       Cipher encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                        encryptCipher.init(Cipher.ENCRYPT_MODE, secret);
-                       decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+                       Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                        decryptCipher.init(Cipher.DECRYPT_MODE, secret);
                        hmac = Mac.getInstance("HmacSHA256");
                        hmac.init(secret);
+                       cloud=new CloudComm(baseurl, encryptCipher, decryptCipher);
                } catch (Exception e) {
                        throw new Error("Failed To Initialize Ciphers");
                }