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.");
+ }
+ }
}