From 102ac8abeab93691d57811bbb4abd763b42c95ba Mon Sep 17 00:00:00 2001 From: Brian Demsky Date: Sat, 23 Jul 2016 01:19:59 -0700 Subject: [PATCH] edits --- src/java/iotcloud/Slot.java | 4 ---- src/java/iotcloud/Table.java | 39 +++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/java/iotcloud/Slot.java b/src/java/iotcloud/Slot.java index 8d12fc2..841e818 100644 --- a/src/java/iotcloud/Slot.java +++ b/src/java/iotcloud/Slot.java @@ -14,10 +14,6 @@ class Slot { long machineid; Vector entries; - Slot(Vector _entries) { - entries=_entries; - } - Slot(long _seqnum, long _machineid, byte[] _prevhmac, byte[] _hmac, Vector _entries) { seqnum=_seqnum; machineid=_machineid; diff --git a/src/java/iotcloud/Table.java b/src/java/iotcloud/Table.java index beceb7c..ad5f69e 100644 --- a/src/java/iotcloud/Table.java +++ b/src/java/iotcloud/Table.java @@ -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."); + } + } } -- 2.34.1