package edu.jhuapl.sages.mobile.lib;

import java.security.NoSuchAlgorithmException;

import javax.crypto.NoSuchPaddingException;

import edu.jhuapl.sages.mobile.lib.crypto.engines.CryptoEngine;

public class SharedObjects {
	
	private static CryptoEngine cryptoEngine;
	
	public SharedObjects() throws NoSuchAlgorithmException, NoSuchPaddingException{
		cryptoEngine = new CryptoEngine("PASSWORD12345678".getBytes());
	}

	/**
	 * The crypto engine to use on both the client and receiver for testing only
	 * @return
	 * @throws NoSuchPaddingException 
	 * @throws NoSuchAlgorithmException 
	 */
	public static CryptoEngine getCryptoEngine() throws NoSuchAlgorithmException, NoSuchPaddingException {
		if (cryptoEngine == null){
			SharedObjects so = new SharedObjects();
		}
		return cryptoEngine;
	}
	
	

}

@@ -126,24 +126,52 @@
 ception;%0D%0A%0D%0A
+import android.util.Log;%0D%0A%0D%0A
 import edu.j
@@ -222,16 +222,88 @@
 Engine;%0D
+%0Aimport edu.jhuapl.sages.mobile.lib.crypto.persisted.SagesKeyException;%0D
 %0A%0D%0Apubli
@@ -854,46 +854,169 @@
 %0A%09%09%09
-SharedObjects so = new SharedObject
+//TODO need to come up with long term solution to handle this. leave null and throw exception?%0D%0A%09%09%09cryptoEngine = new CryptoEngine(%22PASSWORD12345678%22.getByte
 s()
+)
 ;%0D%0A%09
@@ -1051,15 +1051,253 @@
 %09%7D%0D%0A%09%0D%0A%09
+protected static void updateCryptoEngine(String keyVal) throws NoSuchAlgorithmException, NoSuchPaddingException%7B%0D%0A%09%09cryptoEngine = new CryptoEngine(keyVal.getBytes());%0D%0A%09%09Log.i(SharedObjects.class.getName(), %22updated CryptoEnginge.%22);%0D%0A%09%7D
 %0D%0A%0D%0A%7D%0D%0A

initialize null cryptoengine with hardcoded AES-128 bit key