Improve KeyStore functionality
diff --git a/js/WebSocketTransport.js b/js/WebSocketTransport.js
index b9900a8..61df84c 100644
--- a/js/WebSocketTransport.js
+++ b/js/WebSocketTransport.js
@@ -148,7 +148,6 @@
 						//console.log(currentClosure.timerID);
 						
 						// Key verification
-						var verified = false;
 						
 						// Recursive key fetching & verification closure
 						var KeyFetchClosure = function KeyFetchClosure(content, closure, key, signature) {
@@ -165,19 +164,18 @@
 								console.log("In KeyFetchClosure.upcall: interest time out.");
 							} else if (kind == Closure.UPCALL_CONTENT) {
 								console.log("In KeyFetchClosure.upcall: signature verification passed");
-								var keyHex = DataUtils.toHex(upcallInfo.contentObject.content).toLowerCase();
-								//console.log("Key: " + keyHex);
 								
-								var kp = keyHex.slice(56, 314);
-								var exp = keyHex.slice(318, 324);
-								
-								var rsakey = new RSAKey();
-								rsakey.setPublic(kp, exp);
+								var rsakey = decodeSubjectPublicKeyInfo(upcallInfo.contentObject.content);
 								var verified = rsakey.verifyByteArray(this.contentObject.rawSignatureData, this.signature);
 								var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
 								
 								//console.log("raise encapsulated closure");
 								this.closure.upcall(flag, new UpcallInfo(ndn, null, 0, this.contentObject));
+								
+								// Store key in cache
+								var keyEntry = new KeyStoreEntry(keylocator.keyName, rsakey, new Date().getTime());
+								NDN.addKeyEntry(keyEntry);
+								//console.log(NDN.KeyStore);
 							}
 						};
 						
@@ -194,22 +192,17 @@
 								if (nameStr.match(keyname)) {
 									console.log("Content is key itself");
 									
-									var keyHex = DataUtils.toHex(co.content).toLowerCase();
-									console.log("Key content: " + keyHex);
-									
-									var kp = keyHex.slice(56, 314);
-									var exp = keyHex.slice(318, 324);
-									
-									var rsakey = new RSAKey();
-									rsakey.setPublic(kp, exp);
+									var rsakey = decodeSubjectPublicKeyInfo(co.content);
 									var verified = rsakey.verifyByteArray(co.rawSignatureData, sigHex);
 									var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
 									
 									currentClosure.upcall(flag, new UpcallInfo(ndn, null, 0, co));
 									
-									// Store key in cache
-									var keyEntry = new KeyStoreEntry(keylocator.keyName, keyHex, rsakey);
-									NDN.KeyStore.push(keyEntry);
+									// SWT: We don't need to store key here since the same key will be
+									//      stored again in the closure.
+									//var keyEntry = new KeyStoreEntry(keylocator.keyName, rsakey, new Date().getTime());
+									//NDN.addKeyEntry(keyEntry);
+									//console.log(NDN.KeyStore);
 								} else {
 									console.log("Fetch key according to keylocator");
 									
@@ -219,12 +212,11 @@
 										// Key found, verify now
 										console.log("Local key cache hit");
 										var rsakey = keyEntry.rsaKey;
-										verified = rsakey.verifyByteArray(co.rawSignatureData, sigHex);
-										
+										var verified = rsakey.verifyByteArray(co.rawSignatureData, sigHex);
 										var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
 										
 										// Raise callback
-										currentClosure.upcall(Closure.UPCALL_CONTENT, new UpcallInfo(ndn, null, 0, co));
+										currentClosure.upcall(flag, new UpcallInfo(ndn, null, 0, co));
 									} else {
 										// Not found, fetch now
 										var nextClosure = new KeyFetchClosure(co, currentClosure, keyname, sigHex);
@@ -235,24 +227,16 @@
 								}
 							} else if (keylocator.type == KeyLocatorType.KEY) {
 								console.log("Keylocator contains KEY");
-								var publickeyHex = DataUtils.toHex(keylocator.publicKey).toLowerCase();
-								console.log(publickeyHex);
 		
-								var kp = publickeyHex.slice(56, 314);
-								var exp = publickeyHex.slice(318, 324);
-								
-								var rsakey = new RSAKey();
-								rsakey.setPublic(kp, exp);
-								verified = rsakey.verifyByteArray(co.rawSignatureData, sigHex);
-								
+								var rsakey = decodeSubjectPublicKeyInfo(co.signedInfo.locator.publicKey);
+								var verified = rsakey.verifyByteArray(co.rawSignatureData, sigHex);
 								var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
 								
 								// Raise callback
 								currentClosure.upcall(Closure.UPCALL_CONTENT, new UpcallInfo(ndn, null, 0, co));
 								
-								// Store key in cache
-								var keyEntry = new KeyStoreEntry(keylocator.keyName, publickeyHex, rsakey);
-								NDN.KeyStore.push(keyEntry);
+								// Since KeyLocator does not contain key name for this key,
+								// we have no way to store it as a key entry in KeyStore.
 							} else {
 								var cert = keylocator.certificate;
 								console.log("KeyLocator contains CERT");