Security implemented + Partial publish
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..56ce44e
--- /dev/null
+++ b/.DS_Store
Binary files differ
diff --git a/js/.DS_Store b/js/.DS_Store
index d3e1ca3..b373157 100644
--- a/js/.DS_Store
+++ b/js/.DS_Store
Binary files differ
diff --git a/js/CCNTime.js b/js/CCNTime.js
index 26e98df..d4a8098 100644
--- a/js/CCNTime.js
+++ b/js/CCNTime.js
@@ -5,23 +5,21 @@
 
 var CCNTime = function CCNTime(
                                
-		msec) {
+		input) {
 
 
 
 
 	this.NANOS_MAX = 999877929;
 	
-	if(typeof msec =='object'){
-		this.setDateBinary(msec);
-		this.msec = msec;
-		this.msecHex = toHex(msec);
-	}
-	else if(typeof msec =='string'){
-		
-		this.msec = toNumbers(msec);
-		this.setDateBinary(this.msec);
-		this.msecHex = msec;
+	/*if(typeof input =='object'){
+		this.longDate = DataUtils.byteArrayToUnsignedLong(input);
+		this.binaryDate = input;
+	}*/
+	if(typeof input =='number'){
+		this.msec = input;
+		//this.binaryDate = DataUtils.unsignedLongToByteArray(input);
+
 	}
 	else{
 		if(LOG>1) console.log('UNRECOGNIZED TYPE FOR TIME');
@@ -29,6 +27,12 @@
 };
 
 
+CCNTime.prototype.getJavascriptDate = function(){
+	var d = new Date();
+	d.setTime( this.msec );
+	return d
+};
+
 	/**
 	 * Create a CCNTime
 	 * @param timestamp source timestamp to initialize from, some precision will be lost
@@ -39,7 +43,7 @@
 	 * Create a CCNTime from its binary encoding
 	 * @param binaryTime12 the binary representation of a CCNTime
 	 */
-CCNTime.prototype.setDateBinary = function(
+/*CCNTime.prototype.setDateBinary = function(
 	//byte [] 
 		binaryTime12) {
 
@@ -55,8 +59,7 @@
 		b = (binaryTime12[i]) & 0xFF;
 		value |= b;
 	}
-	
-	this.date = value;
+
 	//this.date = new Date(value);
 
 };
@@ -66,7 +69,7 @@
 
 	return this.msec; //unsignedLongToByteArray(this.date.getTime());
 
-}
+}*/
 /*
 unsignedLongToByteArray= function( value) {
 	if( 0 == value )
diff --git a/js/ContentName.js b/js/ContentName.js
index 8c12188..74ce00e 100644
--- a/js/ContentName.js
+++ b/js/ContentName.js
@@ -6,23 +6,15 @@
 
 var ContentName = function ContentName(_Components){
 
-
-	this.SCHEME = "ccnx:";
-
-	this.ORIGINAL_SCHEME = "ccn:";
-
-	this.SEPARATOR = "/";
-	this.ROOT = null;
-	
 	if( typeof _Components == 'string') {
 		
 		if(LOG>3)console.log('Content Name String '+_Components);
-		this.Components = createNameArray(_Components);
+		this.Components = ContentName.makeBlob(ContentName.createNameArray(_Components));
 	}
 	else if(typeof _Components === 'object' && _Components instanceof Array ){
 		
 		if(LOG>4)console.log('Content Name Array '+_Components);
-		this.Components = _Components;
+		this.Components = ContentName.makeBlob(_Components);
 
 	}
 	else if(_Components==null){
@@ -35,10 +27,37 @@
 	}
 };
 
-function createNameArray(name){
+ContentName.prototype.getName=function(){
+	
+	var output = "";
+	
+	for(var i=0;i<this.Components.length;i++){
+		output+= "/"+ DataUtils.toString(this.Components[i]);
+	}
+	
+	return output;
+	
+};
 
-		
-	//message = decodeURIComponent(message);
+ContentName.makeBlob=function(name){
+	
+	var blobArrays = new Array(name.length);
+
+	for(var i=0;i<name.length;i++){
+		if(typeof name[i] == 'string')
+			blobArrays[i]= DataUtils.toNumbersFromString( name[i] );
+		else if(typeof name[i] == 'object')
+			blobArrays[i]= name[i] ;
+		else 
+			if(LOG>4)console.log('NAME COMPONENT INVALID');
+	}
+	
+	return blobArrays;
+};
+
+ContentName.createNameArray=function(name){
+
+
 	name = unescape(name);
 	
 	var array = name.split('/');
diff --git a/js/ContentObject.js b/js/ContentObject.js
index e120a98..0d58ba6 100644
--- a/js/ContentObject.js
+++ b/js/ContentObject.js
@@ -27,30 +27,40 @@
 };
 
 ContentObject.prototype.sign = function(){
+
 	var n1 = this.encodeObject(this.Name);
 	var n2 = this.encodeObject(this.SignedInfo);
 	var n3 = this.encodeContent();
 	
 	var n = n1.concat(n2,n3);
+	
 	if(LOG>2)console.log('Signature Data is (binary) '+n);
 	
-	if(LOG>2)console.log('Signature Data is (RawString) '+ toString(n) );
-	if(LOG>2)console.log(toString(n) );
+	if(LOG>2)console.log('Signature Data is (RawString)');
 	
+	if(LOG>2)console.log( DataUtils.toString(n) );
+	
+	var sig = DataUtils.toString(n);
+
 	
 	var rsa = new RSAKey();
 			
 	rsa.readPrivateKeyFromPEMString(globalKeyManager.privateKey);
-			
-	var hSig = rsa.signString(toString(n), "sha256");
+	
+	//var hSig = rsa.signString(sig, "sha256");
 
+	var hSig = rsa.signByteArrayWithSHA256(n);
+
+	
 	if(LOG>2)console.log('SIGNATURE SAVED IS');
 	
 	if(LOG>2)console.log(hSig);
 	
-	if(LOG>2)console.log(toNumbers(hSig.trim()));
+	if(LOG>2)console.log(  DataUtils.toNumbers(hSig.trim()));
 
-	this.Signature.Signature = toNumbers(hSig.trim());
+	this.Signature.Signature = DataUtils.toNumbers(hSig.trim());
+	
+
 };
 
 ContentObject.prototype.encodeObject = function encodeObject(obj){
@@ -80,21 +90,17 @@
 ContentObject.prototype.saveRawData = function(bytes){
 	
 	var sigBits = bytes.slice(this.StartSIG, this.EndSIG );
-	
-	//var sigIngoPlusContentBits = bytes.slice(this.StartSignedInfo, this.EndContent );
-	
-	//var concat = sigBits.concat(sigIngoPlusContentBits);
-	
-	//this.rawSignatureData = concat;
 
 	this.rawSignatureData = sigBits;
 };
 
 ContentObject.prototype.decode = function(/*XMLDecoder*/ decoder) {
 
+	// TODO VALIDATE THAT ALL FIELDS EXCEPT SIGNATURE ARE PRESENT
+
 		decoder.readStartElement(this.getElementLabel());
 
-		
+
 		if( decoder.peekStartElement(CCNProtocolDTags.Signature) ){
 			this.Signature = new Signature();
 			this.Signature.decode(decoder);
diff --git a/js/FaceInstance.js b/js/FaceInstance.js
index 9f32ade..5cac6bc 100644
--- a/js/FaceInstance.js
+++ b/js/FaceInstance.js
@@ -3,6 +3,7 @@
  * This class represents Face Instances
  */
 
+var NetworkProtocol = { TCP:6, UDP:17};
 
 var FaceInstance  = function FaceInstance(
 	    _Action,
@@ -70,11 +71,11 @@
 		
 		this.IPProto = null;
 		
-		if (NetworkProtocol.TCP.value().intValue() == pI) {
+		if (NetworkProtocol.TCP == pI) {
 			
 			this.IPProto = NetworkProtocol.TCP;
 			
-		} else if (NetworkProtocol.UDP.value().intValue() == pI) {
+		} else if (NetworkProtocol.UDP == pI) {
 			
 			this.IPProto = NetworkProtocol.UDP;
 			
@@ -107,7 +108,6 @@
 	if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
 		this.FreshnessSeconds = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds); 
 	}
-	
 	decoder.readEndElement();
 }
 
@@ -123,8 +123,10 @@
 		//throw new Exception("")
 	//}
 	encoder.writeStartElement(this.getElementLabel());
+	
 	if (null != this.Action && this.Action.length != 0)
 		encoder.writeElement(CCNProtocolDTags.Action, this.Action);	
+	
 	if (null != this.PublisherPublicKeyDigest) {
 		this.PublisherPublicKeyDigest.encode(encoder);
 	}
diff --git a/js/Interest.js b/js/Interest.js
index 3c46887..ab20de1 100644
--- a/js/Interest.js
+++ b/js/Interest.js
@@ -3,15 +3,14 @@
  * This class represents Interest Objects
  */
 
-var Interest = function Interest(_Name,_FaceInstance,_MinSuffixComponents,_MaxSuffixComponents,_PublisherPublicKeyDigest, _Exclude, _ChildSelector,_AnswerOriginKind,_Scope,_InterestLifetime,_Nonce){
-	
-	//Setting fields
+var Interest = function Interest(_Name,_FaceInstance,_MinSuffixComponents,_MaxSuffixComponents,_PublisherID, _Exclude, _ChildSelector,_AnswerOriginKind,_Scope,_InterestLifetime,_Nonce){
+		
 	this.Name = _Name;
 	this.FaceInstance = _FaceInstance;
 	this.MaxSuffixComponents = _MaxSuffixComponents;
 	this.MinSuffixComponents = _MinSuffixComponents;
 	
-	this.PublisherKeyDigest = _PublisherPublicKeyDigest;
+	this.PublisherID = _PublisherID;
 	this.Exclude = _Exclude;
 	this.ChildSelector = _ChildSelector;
 	this.AnswerOriginKind = _AnswerOriginKind;
@@ -49,10 +48,10 @@
 		}
 			
 		//TODO decode PublisherID
-		/*if (PublisherID.peek(decoder)) {
+		if (PublisherID.peek(decoder)) {
 			this.Publisher = new PublisherID();
 			this.Publisher.decode(decoder);
-		}*/
+		}
 
 		if (decoder.peekStartElement(CCNProtocolDTags.Exclude)) {
 			this.Exclude = new Exclude();
@@ -84,9 +83,7 @@
 };
 
 Interest.prototype.encode = function(/*XMLEncoder*/ encoder){
-		/*if (!validate()) {
-			throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
-		}*/
+		//Could check if name is present
 		
 		encoder.writeStartElement(CCNProtocolDTags.Interest);
 		
@@ -100,20 +97,20 @@
 
 		//TODO Encode PublisherID
 		
-		/*if (null != this.PublisherID)
-			publisherID().encode(encoder);*/
+		if (null != this.PublisherID)
+			publisherID().encode(encoder);
 		
 		//TODO Encode Exclude
 		
-		//if (null != this.Exclude)
-			//exclude().encode(encoder);
+		if (null != this.Exclude)
+			exclude().encode(encoder);
 		
 		if (null != this.ChildSelector) 
 			encoder.writeElement(CCNProtocolDTags.ChildSelector, this.ChildSelector);
 
 		//TODO Encode OriginKind
 		if (this.DEFAULT_ANSWER_ORIGIN_KIND != this.AnswerOriginKind && this.AnswerOriginKind!=null) 
-			//encoder.writeElement(CCNProtocolDTags.AnswerOriginKind, this.AnswerOriginKind);
+			encoder.writeElement(CCNProtocolDTags.AnswerOriginKind, this.AnswerOriginKind);
 		
 		if (null != this.Scope) 
 			encoder.writeElement(CCNProtocolDTags.Scope, this.Scope);
diff --git a/js/JavaSocketBridge.jar b/js/JavaSocketBridge.jar
index 0f2deae..c7d0c3b 100644
--- a/js/JavaSocketBridge.jar
+++ b/js/JavaSocketBridge.jar
Binary files differ
diff --git a/js/KeyLocator.js b/js/KeyLocator.js
index d61ed12..9ada28b 100644
--- a/js/KeyLocator.js
+++ b/js/KeyLocator.js
@@ -11,7 +11,6 @@
 
 var KeyLocator = function KeyLocator(_Input,_Type){ 
 
-
     this.Type=_Type;
     
     if (_Type==KeyLocatorType.NAME){
@@ -39,7 +38,7 @@
 				//TODO FIX THIS, This should create a Key Object instead of keeping bytes
 
 				this.PublicKey =   encodedKey;//CryptoUtil.getPublicKey(encodedKey);
-				
+				this.Type = 2;
 				
 
 				if(LOG>4) console.log('PUBLIC KEY FOUND: '+ this.PublicKey);
@@ -67,7 +66,8 @@
 				
 
 				this.Certificate = encodedCert;
-				
+				this.Type = 3;
+
 				if(LOG>4) console.log('CERTIFICATE FOUND: '+ this.Certificate);
 				
 			} catch ( e) {
@@ -77,7 +77,8 @@
 				throw new Exception("Cannot parse certificate! ");
 			}
 		} else  {
-			
+			this.Type = 1;
+
 
 			this.KeyName = new KeyName();
 			this.KeyName.decode(decoder);
@@ -105,7 +106,7 @@
 		} else if (this.Type == KeyLocatorType.CERTIFICATE) {
 			
 			try {
-				encoder.writeElement(CCNProtocolDTags.Certificate, this.Certificate.getEncoded());
+				encoder.writeElement(CCNProtocolDTags.Certificate, this.Certificate);
 			} catch ( e) {
 				throw new Exception("CertificateEncodingException attempting to write key locator: " + e);
 			}
diff --git a/js/KeyName.js b/js/KeyName.js
index 2c79bfc..c156af1 100644
--- a/js/KeyName.js
+++ b/js/KeyName.js
@@ -22,7 +22,7 @@
 	
 	if(LOG>4) console.log('KEY NAME FOUND: ');
 	
-	if ( peek(decoder) ) {
+	if ( PublisherID.peek(decoder) ) {
 		this.PublisherID = new PublisherID();
 		this.PublisherID.decode(decoder);
 	}
diff --git a/js/PublisherID.js b/js/PublisherID.js
index 1e24cc7..1c98435 100644
--- a/js/PublisherID.js
+++ b/js/PublisherID.js
@@ -71,7 +71,7 @@
 	encoder.writeElement(this.getElementLabel(), this.PublisherID);
 };
 	
-var peek = function(
+PublisherID.peek = function(
 	//XMLDecoder 
 		decoder) {
 
diff --git a/js/PublisherPublicKeyDigest.js b/js/PublisherPublicKeyDigest.js
index adbc25c..5b0ac7f 100644
--- a/js/PublisherPublicKeyDigest.js
+++ b/js/PublisherPublicKeyDigest.js
@@ -4,20 +4,16 @@
  */
 var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){ 
 	
-	
- 	 this.PUBLISHER_ID_LEN = 256/8;
+ 	 //this.PUBLISHER_ID_LEN = 256/8;
+	 this.PUBLISHER_ID_LEN = 512/8;
  	 
+
 	 this.PublisherPublicKeyDigest = _pkd;
  	 //if( typeof _pkd == "object") this.PublisherPublicKeyDigest = _pkd; // Byte Array
  	 //else if( typeof _pkd == "PublicKey") ;//TODO...
     
- 	 
-
 };
 
-
-
-
 PublisherPublicKeyDigest.prototype.decode = function( decoder) {		
 
 		this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
@@ -41,9 +37,9 @@
 
 PublisherPublicKeyDigest.prototype.encode= function( encoder) {
 		//TODO Check that the ByteArray for the key is present
-		/*if (!this.validate()) {
+		if (!this.validate()) {
 			throw new Exception("Cannot encode : field values missing.");
-		}*/
+		}
 		if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.PublisherPublicKeyDigest);
 		encoder.writeElement(this.getElementLabel(), this.PublisherPublicKeyDigest);
 };
@@ -51,5 +47,5 @@
 PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
 
 PublisherPublicKeyDigest.prototype.validate =function() {
-		return (null != this.PublisherKeyDigest);
+		return (null != this.PublisherPublicKeyDigest);
 };
diff --git a/js/Signature.js b/js/Signature.js
index f8f4d69..9dcbbc5 100644
--- a/js/Signature.js
+++ b/js/Signature.js
@@ -48,12 +48,10 @@
 		
 		//FORCE TO READ A SIGNATURE
 
-		//if (decoder.peekStartElement(CCNProtocolDTags.SignatureBits)) {
 			//if(LOG>4)console.log('SIGNATURE FOUND ');
 			this.Signature = decoder.readBinaryElement(CCNProtocolDTags.SignatureBits);	
+			if(LOG>4)console.log('READ SIGNATURE ');
 
-		//}
-		
 		decoder.readEndElement();
 	
 };
diff --git a/js/SignedInfo.js b/js/SignedInfo.js
index 0b81201..b2ff0b2 100644
--- a/js/SignedInfo.js
+++ b/js/SignedInfo.js
@@ -26,25 +26,55 @@
 SignedInfo.prototype.setFields = function(){
 	//BASE64 -> RAW STRING
 	
-	var stringCertificate = DataUtils.base64toString(globalKeyManager.certificate);
+	//this.Locator = new KeyLocator(  DataUtils.toNumbersFromString(stringCertificate)  ,KeyLocatorType.CERTIFICATE );
 	
-	if(LOG>3)console.log('string Certificate is '+stringCertificate);
+	var publicKeyHex = globalKeyManager.publicKey;
+
+	console.log('PUBLIC KEY TO WRITE TO CONTENT OBJECT IS ');
+	console.log(publicKeyHex);
+	
+	var publicKeyBytes = DataUtils.toNumbers(globalKeyManager.publicKey) ; 
+
+	
+
+	//var stringCertificate = DataUtils.base64toString(globalKeyManager.certificate);
+	
+	//if(LOG>3)console.log('string Certificate is '+stringCertificate);
 
 	//HEX -> BYTE ARRAY
-	var publisherkey = toNumbers(hex_sha256(stringCertificate));
+	//var publisherkey = DataUtils.toNumbers(hex_sha256(stringCertificate));
 	
-	if(LOG>3)console.log('publisher key is ');
-	if(LOG>3)console.log(publisherkey);
+	//if(LOG>3)console.log('publisher key is ');
+	//if(LOG>3)console.log(publisherkey);
 	
-	this.Publisher = new PublisherPublicKeyDigest(publisherkey);
+	var publisherKeyDigest = hex_sha256_from_bytes(publicKeyBytes);
 
+	this.Publisher = new PublisherPublicKeyDigest(  DataUtils.toNumbers(  publisherKeyDigest )  );
 	
-	this.Timestamp = new CCNTime('FD0499602d2000');
+	//this.Publisher = new PublisherPublicKeyDigest(publisherkey);
+
+	var d = new Date();
 	
-	this.Type = ContentType.DATA;
+	var time = d.getTime();
 	
-	console.log('toNumbersFromString(stringCertificate) '+toNumbersFromString(stringCertificate));
-	this.Locator = new KeyLocator(  toNumbersFromString(stringCertificate)  ,KeyLocatorType.KEY );
+
+    this.Timestamp = new CCNTime( time );
+    
+    if(LOG>4)console.log('TIME msec is');
+
+    if(LOG>4)console.log(this.Timestamp.msec);
+
+    //DATA
+	this.Type = 0;//0x0C04C0;//ContentTypeValue[ContentType.DATA];
+	
+	//if(LOG>4)console.log('toNumbersFromString(stringCertificate) '+DataUtils.toNumbersFromString(stringCertificate));
+	
+	console.log('PUBLIC KEY TO WRITE TO CONTENT OBJECT IS ');
+	console.log(publicKeyBytes);
+
+	this.Locator = new KeyLocator(  publicKeyBytes  ,KeyLocatorType.KEY );
+
+	//this.Locator = new KeyLocator(  DataUtils.toNumbersFromString(stringCertificate)  ,KeyLocatorType.CERTIFICATE );
 
 };
 
@@ -67,12 +97,12 @@
 		if (decoder.peekStartElement(CCNProtocolDTags.Type)) {
 			binType = decoder.readBinaryElement(CCNProtocolDTags.Type);//byte [] 
 		
-		
+			
 			//TODO Implement Type of Key Reading
 			
-			if(LOG>4)console.log('TYPE IS'+bintype);
+			if(LOG>4)console.log('Binary Type of of Signed Info is '+binType);
 
-			this.Type = this.valueToType(binType);
+			this.Type = binType;
 			
 			
 			//TODO Implement Type of Key Reading
@@ -116,7 +146,7 @@
 		}
 
 		if (null!=this.Timestamp) {
-			encoder.writeDateTime(CCNProtocolDTags.Timestamp, this.Timestamp);
+			encoder.writeDateTime(CCNProtocolDTags.Timestamp, this.Timestamp );
 		}
 		
 		if (null!=this.Type && this.Type !=0) {
diff --git a/js/encoding/BinaryXMLDecoder.js b/js/encoding/BinaryXMLDecoder.js
index 1175f28..c41d549 100644
--- a/js/encoding/BinaryXMLDecoder.js
+++ b/js/encoding/BinaryXMLDecoder.js
@@ -451,16 +451,24 @@
 	
 	
 BinaryXMLDecoder.prototype.readEndElement = function(){
-		try {
+		//try {
+			if(LOG>4)console.log('this.offset is '+this.offset);
+			
 			var next = this.istream[this.offset]; 
+			
 			this.offset++;
 			//read();
+			
+			if(LOG>4)console.log('XML_CLOSE IS '+XML_CLOSE);
+			if(LOG>4)console.log('next is '+next);
+			
 			if (next != XML_CLOSE) {
+				console.log("Expected end element, got: " + next);
 				throw new ContentDecodingException("Expected end element, got: " + next);
 			}
-		} catch ( e) {
-			throw new ContentDecodingException(e);
-		}
+		//} catch ( e) {
+			//throw new ContentDecodingException(e);
+		//}
 	};
 
 
@@ -491,9 +499,25 @@
 	startTag)  {
 	//byte [] 
 	
-	byteTimestamp = this.readBinaryElement(startTag);
+	var byteTimestamp = this.readBinaryElement(startTag);
+
+	//var lontimestamp = DataUtils.byteArrayToUnsignedLong(byteTimestamp);
+
+	var byteTimestamp = DataUtils.toHex(byteTimestamp);
+	
+	
+	var byteTimestamp = parseInt(byteTimestamp, 16);
+
+	lontimestamp = (byteTimestamp/ 4096) * 1000;
+
+	//if(lontimestamp<0) lontimestamp =  - lontimestamp;
+
+	if(LOG>3) console.log('DECODED DATE WITH VALUE');
+	if(LOG>3) console.log(lontimestamp);
+	
+
 	//CCNTime 
-	timestamp = new CCNTime(byteTimestamp);
+	timestamp = new CCNTime(lontimestamp);
 	//timestamp.setDateBinary(byteTimestamp);
 	
 	if (null == timestamp) {
@@ -544,6 +568,8 @@
 		
 	} while (more);
 	
+	if(LOG>3)console.log('TYPE is '+ type + ' VAL is '+ val);
+
 	return new TypeAndVal(type, val);
 };
 
@@ -608,7 +634,7 @@
 
 };
 
-
+var count =0;
 
 //String
 BinaryXMLDecoder.prototype.decodeUString = function(
@@ -617,7 +643,12 @@
 		//int 
 		byteLength) {
 	
-	if(null == byteLength){
+	/*
+	console.log('COUNT IS '+count);
+	console.log('INPUT BYTELENGTH IS '+byteLength);
+	count++;
+	if(null == byteLength||  undefined == byteLength){
+		console.log("!!!!");
 		tv = this.decodeTypeAndVal(this.istream);
 		var valval ;
 		if(typeof tv.val() == 'string'){
@@ -626,18 +657,82 @@
 		else
 			valval = (tv.val());
 		
+		if(LOG>4) console.log('valval  is ' + valval);
 		byteLength= this.decodeUString(this.istream, valval);
+		
+		//if(LOG>4) console.log('byte Length found in type val is '+ byteLength.charCodeAt(0));
+		byteLength = parseInt(byteLength);
+		
+		
+		//byteLength = byteLength.charCodeAt(0);
+		//if(LOG>4) console.log('byte Length found in type val is '+ byteLength);
 	}
-
+	if(LOG>4)console.log('byteLength is '+byteLength);
+	if(LOG>4)console.log('type of byteLength is '+typeof byteLength);
+	
 	stringBytes = this.decodeBlob(this.istream, byteLength);
 	
+	//console.log('String bytes are '+ stringBytes);
+	//console.log('stringBytes);
+	
+	if(LOG>4)console.log('byteLength is '+byteLength);
+	if(LOG>4)console.log('this.offset is '+this.offset);
+
 	tempBuffer = this.istream.slice(this.offset, this.offset+byteLength);
+	if(LOG>4)console.log('TEMPBUFFER IS' + tempBuffer);
+	if(LOG>4)console.log( tempBuffer);
+
+	if(LOG>4)console.log('ADDING to offset value' + byteLength);
 	this.offset+= byteLength;
-	console.log('read the String' + tempBuffer.toString('ascii'));
-	return tempBuffer.toString('ascii');//DataUtils.getUTF8StringFromBytes(stringBytes);
+	//if(LOG>3)console.log('read the String' + tempBuffer.toString('ascii'));
+	//return tempBuffer.toString('ascii');//
+	
+	
+	//if(LOG>3)console.log( 'STRING READ IS '+ DataUtils.getUTF8StringFromBytes(stringBytes) ) ;
+	//if(LOG>3)console.log( 'STRING READ IS '+ DataUtils.getUTF8StringFromBytes(tempBuffer) ) ;
+	//if(LOG>3)console.log(DataUtils.getUTF8StringFromBytes(tempBuffer) ) ;
+	//return DataUtils.getUTF8StringFromBytes(tempBuffer);
+	
+	if(LOG>3)console.log( 'STRING READ IS '+ DataUtils.toString(stringBytes) ) ;
+	if(LOG>3)console.log( 'TYPE OF STRING READ IS '+ typeof DataUtils.toString(stringBytes) ) ;
+
+	return  DataUtils.toString(stringBytes);*/
+
+	if(null == byteLength ){
+		var tempStreamPosition = this.offset;
+			
+		//TypeAndVal 
+		tv = this.decodeTypeAndVal(istream);
+		
+		if(LOG>3)console.log('TV is '+tv);
+		if(LOG>3)console.log(tv);
+		
+		if(LOG>3)console.log('Type of TV is '+typeof tv);
+	
+		if ((null == tv) || (XML_UDATA != tv.type())) { // if we just have closers left, will get back null
+			//if (Log.isLoggable(Log.FAC_ENCODING, Level.FINEST))
+				//Log.finest(Log.FAC_ENCODING, "Expected UDATA, got " + ((null == tv) ? " not a tag " : tv.type()) + ", assuming elided 0-length blob.");
+			
+			this.offset = tempStreamPosition;
+			
+			return "";
+		}
+			
+		return this.decodeUString(istream, tv.val());
+	}
+	else{
+		//byte [] 
+		stringBytes = this.decodeBlob(istream, byteLength);
+		
+		//return DataUtils.getUTF8StringFromBytes(stringBytes);
+		return  DataUtils.toString(stringBytes);
+		
+	}
 };
 
 
+
+
 //OBject containg a pair of type and value
 var TypeAndVal = function TypeAndVal(_type,_val) {
 	this.t = _type;
@@ -651,4 +746,43 @@
 TypeAndVal.prototype.val = function(){
 	return this.v;
 };
-//TODO
\ No newline at end of file
+//TODO
+
+
+
+
+
+
+BinaryXMLDecoder.prototype.readIntegerElement =function(
+	//String 
+	startTag) {
+
+	//String 
+	if(LOG>4) console.log('READING INTEGER '+ startTag);
+	if(LOG>4) console.log('TYPE OF '+ typeof startTag);
+	
+	//try {
+		
+	strVal = this.readUTF8Element(startTag);
+
+	//}
+	//catch (e) {
+		//throw new Exception("Cannot parse " + startTag + ": " + strVal);
+	//}
+	
+	return parseInt(strVal);
+};
+
+
+BinaryXMLDecoder.prototype.readUTF8Element =function(
+			//String 
+			startTag,
+			//TreeMap<String, String> 
+			attributes) {
+			//throws ContentDecodingException 
+
+		this.readStartElement(startTag, attributes); // can't use getElementText, can't get attributes
+		//String 
+		strElementText = this.readUString();
+		return strElementText;
+};
diff --git a/js/encoding/BinaryXMLEncoder.js b/js/encoding/BinaryXMLEncoder.js
index a633aa8..16759b1 100644
--- a/js/encoding/BinaryXMLEncoder.js
+++ b/js/encoding/BinaryXMLEncoder.js
@@ -51,7 +51,7 @@
 };
 
 BinaryXMLEncoder.prototype.writeUString = function(/*String*/ utf8Content){
-	this.encodeUString(this.ostream, utf8Content);
+	this.encodeUString(this.ostream, utf8Content, XML_UDATA);
 };
 
 BinaryXMLEncoder.prototype.writeBlob = function(/*byte []*/ binaryContent
@@ -149,22 +149,35 @@
 		Content,
 		//TreeMap<String, String> 
 		attributes) {
+	
 	this.writeStartElement(tag, attributes);
 	// Will omit if 0-length
 	
 	if(typeof Content === 'number') {
-		if(LOG>4) console.log('GOING TO WRITE THE NUMBER ' +Content );
-		this.writeBlob(Content.toString());
+		if(LOG>4) console.log('GOING TO WRITE THE NUMBER .charCodeAt(0) ' +Content.toString().charCodeAt(0) );
+		if(LOG>4) console.log('GOING TO WRITE THE NUMBER ' +Content.toString() );
+		if(LOG>4) console.log('type of number is ' +typeof Content.toString() );
+		
+
+		
+		this.writeUString(Content.toString());
 		//whatever
 		
 	}
 	
+	else if(typeof Content === 'string'){
+		if(LOG>4) console.log('GOING TO WRITE THE STRING  ' +Content );
+		if(LOG>4) console.log('type of STRING is ' +typeof Content );
+		
+		this.writeUString(Content);
+	}
+	
 	else{
 	//else if(typeof Content === 'string'){
 		 //console.log('went here');
 		//this.writeBlob(Content);
 	//}
-	
+	if(LOG>4) console.log('GOING TO WRITE A BLOB  ' +Content );
 	//else if(typeof Content === 'object'){
 		this.writeBlob(Content);
 	//}
@@ -189,7 +202,9 @@
 		//byte [] 
 		buf) {
 	
-	console.log('Encoding type '+ type+ ' and value '+ val);
+	if(LOG>4)console.log('Encoding type '+ type+ ' and value '+ val);
+	
+	if(LOG>4) console.log('OFFSET IS ' + this.offset );
 	
 	if ((type > XML_UDATA) || (type < 0) || (val < 0)) {
 		throw new Exception("Tag and value must be positive, and tag valid.");
@@ -248,12 +263,22 @@
 	//byte [] data utils
 	/*custom*/
 	//byte[]
-	strBytes = new Array(ustring.Length);
-	var i = 0;
-	for( ;i<ustring.lengh;i++) //in InStr.ToCharArray())
+	
+	if(LOG>3) console.log("The string to write is ");
+	
+	if(LOG>3) console.log(ustring);
+
+	//COPY THE STRING TO AVOID PROBLEMS
+	strBytes = new Array(ustring.length);
+	
+	var i = 0;	
+
+	for( ; i<ustring.length; i++) //in InStr.ToCharArray())
 	{
-		strBytes[i] = ustring[i];
+		if(LOG>3)console.log("ustring[" + i + '] = ' + ustring[i]);
+		strBytes[i] = ustring.charCodeAt(i);
 	}
+	
 	//strBytes = DataUtils.getBytesFromUTF8String(ustring);
 	
 	this.encodeTypeAndVal(type, 
@@ -261,7 +286,10 @@
 								(strBytes.length-1) :
 								strBytes.length), ostream);
 	
-
+	if(LOG>3) console.log("THE string to write is ");
+	
+	if(LOG>3) console.log(strBytes);
+	
 	this.writeString(strBytes,this.offset);
 	
 	this.offset+= strBytes.length;
@@ -286,12 +314,21 @@
 		return;
 	}
 	
+	if(LOG>4) console.log('LENGTH OF XML_BLOB IS '+length);
 	
+	
+	blobCopy = new Array(blob.Length);
+	var i = 0;
+	for( ;i<blob.length;i++) //in InStr.ToCharArray())
+	{
+		blobCopy[i] = blob[i];
+	}
+
 	this.encodeTypeAndVal(XML_BLOB, length, ostream,offset);
 	
 	if (null != blob) {
 
-		this.writeString(blob,this.offset);
+		this.writeBlobArray(blobCopy,this.offset);
 		this.offset += length;
 	}
 };
@@ -324,7 +361,29 @@
 		tag, 
 		//CCNTime 
 		dateTime) {
-	this.writeElement(tag, dateTime.toBinaryTime());
+	
+	if(LOG>4)console.log('ENCODING DATE with LONG VALUE');
+	if(LOG>4)console.log(dateTime.msec);
+	
+	//var binarydate = DataUtils.unsignedLongToByteArray( Math.round((dateTime.msec/1000) * 4096)  );
+	
+
+	//parse to hex
+	var binarydate =  Math.round((dateTime.msec/1000) * 4096).toString(16)  ;
+
+	//HACK
+	var binarydate =  DataUtils.toNumbers( '0'.concat(binarydate,'0')) ;
+
+	
+	if(LOG>4)console.log('ENCODING DATE with BINARY VALUE');
+	if(LOG>4)console.log(binarydate);
+	
+	if(LOG>4)console.log('ENCODING DATE with BINARY VALUE(HEX)');
+	if(LOG>4)console.log(DataUtils.toHex(binarydate));
+	
+
+	this.writeElement(tag, binarydate);
+
 };
 
 BinaryXMLEncoder.prototype.writeString = function(
@@ -336,16 +395,27 @@
     if(typeof input === 'string'){
 		//console.log('went here');
     	if(LOG>4) console.log('GOING TO WRITE A STRING');
-    
+    	if(LOG>4) console.log(input);
+        
 		for (var i = 0; i < input.length; i++) {
+			if(LOG>4) console.log('input.charCodeAt(i)=' + input.charCodeAt(i));
 		    this.ostream[this.offset+i] = (input.charCodeAt(i));
 		}
 	}
     
+    else{
+    	
+    	if(LOG>4) console.log('GOING TO WRITE A STRING IN BINARY FORM');
+    	if(LOG>4) console.log(input);
+    	
+    	this.writeBlobArray(input);
+    	
+    }
+    /*
 	else if(typeof input === 'object'){
-		this.writeBlobArray(input);
+		
 	}	
-
+	*/
 };
 
 BinaryXMLEncoder.prototype.writeBlobArray = function(
diff --git a/js/encoding/DataUtils.js b/js/encoding/DataUtils.js
index 5386698..1f998af 100644
--- a/js/encoding/DataUtils.js
+++ b/js/encoding/DataUtils.js
@@ -15,12 +15,16 @@
  * 
  */
 
-  var keyStr = "ABCDEFGHIJKLMNOP" +
+DataUtils.keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";
 
+               
+/**
+ * Raw String to Base 64
+ */
 DataUtils.stringtoBase64=function stringtoBase64(input) {
      input = escape(input);
      var output = "";
@@ -45,10 +49,10 @@
         }
 
         output = output +
-           keyStr.charAt(enc1) +
-           keyStr.charAt(enc2) +
-           keyStr.charAt(enc3) +
-           keyStr.charAt(enc4);
+           DataUtils.keyStr.charAt(enc1) +
+           DataUtils.keyStr.charAt(enc2) +
+           DataUtils.keyStr.charAt(enc3) +
+           DataUtils.keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);
@@ -56,6 +60,9 @@
      return output;
   }
 
+/**
+ * Base 64 to Raw String 
+ */
 DataUtils.base64toString = function base64toString(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
@@ -69,13 +76,14 @@
               "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
               "Expect errors in decoding.");
      }
+     
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
      do {
-        enc1 = keyStr.indexOf(input.charAt(i++));
-        enc2 = keyStr.indexOf(input.charAt(i++));
-        enc3 = keyStr.indexOf(input.charAt(i++));
-        enc4 = keyStr.indexOf(input.charAt(i++));
+        enc1 = DataUtils.keyStr.indexOf(input.charAt(i++));
+        enc2 = DataUtils.keyStr.indexOf(input.charAt(i++));
+        enc3 = DataUtils.keyStr.indexOf(input.charAt(i++));
+        enc4 = DataUtils.keyStr.indexOf(input.charAt(i++));
 
         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
@@ -99,39 +107,94 @@
   };
 
 //byte [] 
-DataUtils.prototype.unsignedLongToByteArray= function( value) {
+
+/**
+ * NOT WORKING!!!!!
+ * 
+ * Unsiged Long Number to Byte Array
+ */
+	
+ /*
+DataUtils.unsignedLongToByteArray= function( value) {
+	
+	if(LOG>4)console.log('INPUT IS '+value);
+	
 	if( 0 == value )
 		return [0];
 
 	if( 0 <= value && value <= 0x00FF ) {
 		//byte [] 
-		bb = new Array[1];
+		var bb = new Array(1);
 		bb[0] = (value & 0x00FF);
 		return bb;
 	}
 
-	
+	if(LOG>4) console.log('type of value is '+typeof value);
+	if(LOG>4) console.log('value is '+value);
 	//byte [] 
-	out = null;
+	var out = null;
 	//int
 	var offset = -1;
 	for(var i = 7; i >=0; --i) {
 		//byte
-		b = ((value >> (i * 8)) & 0xFF);
+		console.log(i);
+		console.log('value is '+value);
+		console.log('(value >> (i * 8)) '+ (value >> (i * 8))  );
+		console.log(' ((value >> (i * 8)) & 0xFF) '+ ((value >> (i * 8)) & 0xFF)  );
+
+		var b = ((value >> (i * 8)) & 0xFF)  ;
+		
+		if(LOG>4) console.log('b is '+b);
+		
 		if( out == null && b != 0 ) {
-			out = new byte[i+1];
+			//out = new byte[i+1];
+			out = new Array(i+1);
 			offset = i;
 		}
+		
 		if( out != null )
 			out[ offset - i ] = b;
 	}
+	if(LOG>4)console.log('OUTPUT IS ');
+	if(LOG>4)console.log(out);
 	return out;
 }
+*/
+	
+/**
+ * NOT WORKING!!!!!
+ * 
+ * Unsiged Long Number to Byte Array
+ *//*
+DataUtils.byteArrayToUnsignedLong = function(//final byte [] 
+	src) {
+		if(LOG>4) console.log('INPUT IS ');
+		if(LOG>4) console.log(src);
+		
+		var value = 0;
+		for(var i = 0; i < src.length; i++) {
+			value = value << 8;
+			// Java will assume the byte is signed, so extend it and trim it.
+			
+			
+			var b = ((src[i]) & 0xFF );
+			value |= b;
+		}
+		
+		if(LOG>4) console.log('OUTPUT IS ');
+		
+		if(LOG>4) console.log(value);
+
+		return value;
+	}*/
 
 
-var utf8 = {}
-
-utf8.toByteArray = function(str) {
+/**
+ * Hex String to Byte Array
+ */
+	//THIS IS NOT WORKING
+/*
+DataUtils.HexStringtoByteArray = function(str) {
     var byteArray = [];
     for (var i = 0; i < str.length; i++)
         if (str.charCodeAt(i) <= 0x7F)
@@ -143,8 +206,12 @@
         }
     return byteArray;
 };
-
-utf8.parse = function(byteArray) {
+*/
+	
+/**
+ * Byte Array to Hex String
+ */
+DataUtils.byteArrayToHexString = function(byteArray) {
     var str = '';
     for (var i = 0; i < byteArray.length; i++)
         str +=  byteArray[i] <= 0x7F?
@@ -155,17 +222,24 @@
 };
 
 
+/**
+ * Byte array to Hex String
+ */
 //http://ejohn.org/blog/numbers-hex-and-colors/
-function toHex(arguments){
+DataUtils.toHex = function(arguments){
+	if(LOG>4) console.log('ABOUT TO CONVERT '+ arguments);
   //console.log(arguments);
   var ret = "";
   for ( var i = 0; i < arguments.length; i++ )
     ret += (arguments[i] < 16 ? "0" : "") + arguments[i].toString(16);
-  return ret.toUpperCase();
+  return ret; //.toUpperCase();
 }
 
+/**
+ * Byte array to raw string
+ */
 //DOES NOT SEEM TO WORK
-function toString(arguments){
+DataUtils.toString = function(arguments){
   //console.log(arguments);
   var ret = "";
   for ( var i = 0; i < arguments.length; i++ )
@@ -173,7 +247,10 @@
   return ret;
 }
 
-function toNumbers( str ){
+/**
+ * Hex String to byte array
+ */
+DataUtils.toNumbers=function( str ){
 	if(typeof str =='string'){
 		  var ret = [];
 		   str.replace(/(..)/g, function(str){
@@ -183,9 +260,115 @@
     }
 }
 
-function toNumbersFromString( str ){
+/**
+ * Raw String to Byte Array
+ */
+DataUtils.toNumbersFromString = function( str ){
 	var bytes = new Array(str.length);
 	for(var i=0;i<str.length;i++)
 		bytes[i] = str.charCodeAt(i);
 	return bytes;
-}
\ No newline at end of file
+}
+
+DataUtils.encodeUtf8 = function (string) {
+		string = string.replace(/\r\n/g,"\n");
+		var utftext = "";
+ 
+		for (var n = 0; n < string.length; n++) {
+ 
+			var c = string.charCodeAt(n);
+ 
+			if (c < 128) {
+				utftext += String.fromCharCode(c);
+			}
+			else if((c > 127) && (c < 2048)) {
+				utftext += String.fromCharCode((c >> 6) | 192);
+				utftext += String.fromCharCode((c & 63) | 128);
+			}
+			else {
+				utftext += String.fromCharCode((c >> 12) | 224);
+				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+				utftext += String.fromCharCode((c & 63) | 128);
+			}
+ 
+		}
+ 
+		return utftext;
+	};
+ 
+	// public method for url decoding
+DataUtils.decodeUtf8 = function (utftext) {
+		var string = "";
+		var i = 0;
+		var c = c1 = c2 = 0;
+ 
+		while ( i < utftext.length ) {
+ 
+			c = utftext.charCodeAt(i);
+ 
+			if (c < 128) {
+				string += String.fromCharCode(c);
+				i++;
+			}
+			else if((c > 191) && (c < 224)) {
+				c2 = utftext.charCodeAt(i+1);
+				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
+				i += 2;
+			}
+			else {
+				c2 = utftext.charCodeAt(i+1);
+				c3 = utftext.charCodeAt(i+2);
+				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
+				i += 3;
+			}
+ 
+		}
+ 
+		return string;
+	};
+
+	test = function(){
+		console.log(DataUtils.decodeUtf8("HELLO.~"));
+		return DataUtils.decodeUtf8("HELLO.~");
+	}
+
+//NOT WORKING
+/*
+DataUtils.getUTF8StringFromBytes = function(bytes) {
+	
+	bytes = toString(bytes);
+
+    var ix = 0;
+ 
+    if( bytes.slice(0,3) == "\xEF\xBB\xBF") {
+        ix = 3;
+    }
+ 
+    var string = "";
+    for( ; ix < bytes.length; ix++ ) {
+        var byte1 = bytes[ix].charCodeAt(0);
+        if( byte1 < 0x80 ) {
+            string += String.fromCharCode(byte1);
+        } else if( byte1 >= 0xC2 && byte1 < 0xE0 ) {
+            var byte2 = bytes[++ix].charCodeAt(0);
+            string += String.fromCharCode(((byte1&0x1F)<<6) + (byte2&0x3F));
+        } else if( byte1 >= 0xE0 && byte1 < 0xF0 ) {
+            var byte2 = bytes[++ix].charCodeAt(0);
+            var byte3 = bytes[++ix].charCodeAt(0);
+            string += String.fromCharCode(((byte1&0xFF)<<12) + ((byte2&0x3F)<<6) + (byte3&0x3F));
+        } else if( byte1 >= 0xF0 && byte1 < 0xF5) {
+            var byte2 = bytes[++ix].charCodeAt(0);
+            var byte3 = bytes[++ix].charCodeAt(0);
+            var byte4 = bytes[++ix].charCodeAt(0);
+            var codepoint = ((byte1&0x07)<<18) + ((byte2&0x3F)<<12)+ ((byte3&0x3F)<<6) + (byte4&0x3F);
+            codepoint -= 0x10000;
+            string += String.fromCharCode(
+                (codepoint>>10) + 0xD800,
+                (codepoint&0x3FF) + 0xDC00
+            );
+        }
+    }
+ 
+    return string;
+}*/
+
diff --git a/js/encoding/EncodingUtils.js b/js/encoding/EncodingUtils.js
new file mode 100644
index 0000000..503cd66
--- /dev/null
+++ b/js/encoding/EncodingUtils.js
@@ -0,0 +1,120 @@
+
+
+
+
+function encodeToHexInterest(int){
+	
+	var enc = new BinaryXMLEncoder();
+ 
+	int.encode(enc);
+	
+	var hex = DataUtils.toHex(enc.getReducedOstream());
+
+	return hex;
+
+	
+}
+
+
+function encodeToHexContentObject(co){
+	var enc = new BinaryXMLEncoder();
+ 
+	co.encode(enc);
+	
+	var hex = DataUtils.toHex(enc.getReducedOstream());
+
+	return hex;
+
+	
+}
+
+function encodeToBinaryContentObject(co){
+	var enc = new BinaryXMLEncoder();
+ 
+	co.encode(enc);
+	
+	var hex = enc.getReducedOstream();
+
+	return hex;
+
+	
+}
+
+function encodeForwardingEntry(co){
+	var enc = new BinaryXMLEncoder();
+ 
+	co.encode(enc);
+	
+	var bytes = enc.getReducedOstream();
+
+	return bytes;
+
+	
+}
+
+
+
+function decodeHexFaceInstance(result){
+	
+	var numbers = DataUtils.toNumbers(result);
+			
+	
+	decoder = new BinaryXMLDecoder(numbers);
+	
+	if(LOG>3)console.log('DECODING HEX FACE INSTANCE  \n'+numbers);
+
+	i = new FaceInstance();
+
+	i.decode(decoder);
+
+	return i;
+	
+}
+
+function decodeHexInterest(result){
+	var numbers = DataUtils.toNumbers(result);
+			
+	
+	decoder = new BinaryXMLDecoder(numbers);
+	if(LOG>3)console.log('DECODING HEX INTERST  \n'+numbers);
+
+	i = new Interest();
+
+	i.decode(decoder);
+
+	return i;
+	
+}
+
+
+
+function decodeHexContentObject(result){
+	var numbers = DataUtils.toNumbers(result);
+
+	decoder = new BinaryXMLDecoder(numbers);
+	if(LOG>3)console.log('DECODED HEX CONTENT OBJECT \n'+numbers);
+	
+	co = new ContentObject();
+
+	co.decode(decoder);
+
+	return co;
+	
+}
+
+
+
+function decodeHexForwardingEntry(result){
+	var numbers = DataUtils.toNumbers(result);
+
+	decoder = new BinaryXMLDecoder(numbers);
+	
+	if(LOG>3)console.log('DECODED HEX FORWARDING ENTRY \n'+numbers);
+	
+	co = new ForwardingEntry();
+
+	co.decode(decoder);
+
+	return co;
+	
+}
\ No newline at end of file
diff --git a/js/encoding/TextXMLCodec.js b/js/encoding/TextXMLCodec.js
index 716aa6d..37cbe04 100644
--- a/js/encoding/TextXMLCodec.js
+++ b/js/encoding/TextXMLCodec.js
@@ -22,38 +22,3 @@
 
 };
 
-//returns a string
-
-TextXMLCodec.protpotype.codecName = function() { return this.CODEC_NAME; }	;
-
-//returns a string
-TextXMLCodec.protottype.encodeBinaryElement = function(/*byte []*/ element) {
-		if ((null == element) || (0 == element.length)) 
-			return new String("");
-		return new String(DataUtils.base64Encode(element));
-	};
-	
-/* returns a string */
-TextXMLCodec.prototype.encodeBinaryElement = function(/*byte []*/ element, /*int*/ offset, /*int*/ length) {
-		if ((null == element) || (0 == element.length)) 
-			return new String("");
-		ByteBuffer bbuf = ByteBuffer.wrap(element, offset, length);
-		return new String(DataUtils.base64Encode(bbuf.array()));
-	};
-
-/*returns a byte array*/
-TextXMLCodec.prototype.decodeBinaryElement = function(/*String*/ element) {
-		if ((null == element) || (0 == element.length()))
-			return new byte[0];
-		return DataUtils.base64Decode(element.getBytes());
-	}; 
-
-	
-/*
-	Decode Data
-*/
-	
-
-/*
-	Encode Date
-*/ 
\ No newline at end of file
diff --git a/js/encoding/TextXMLDecoder.js b/js/encoding/TextXMLDecoder.js
index 6af8be3..006ce83 100644
--- a/js/encoding/TextXMLDecoder.js
+++ b/js/encoding/TextXMLDecoder.js
@@ -12,221 +12,3 @@
 	
 };
 
-
-exports.TextXMLDecoder = TextXMLDecoder;
-
-
-exports.prototype.initializeDecoding = function(){
-	try {
-		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
-        factory.setNamespaceAware(true);
-		_reader = factory.newPullParser();
-		_reader.setInput(_istream, null);
-	} catch (XmlPullParserException e) {
-		throw new ContentDecodingException(e.getMessage(), e);
-	}		
-};
-
-exports.prototype.readStartDocument = function(){
-	try {
-		int event = _reader.getEventType();
-		_reader.next();
-		if (event != XmlPullParser.START_DOCUMENT) {
-			throw new ContentDecodingException("Expected start document, got: " + XmlPullParser.TYPES[event]);
-		}
-	} catch (XmlPullParserException e) {
-		throw new ContentDecodingException(e.getMessage(), e);
-	} catch (IOException e) {
-		throw new ContentDecodingException(e.getMessage(), e);
-	}
-};
-
-public void readEndDocument() throws ContentDecodingException {
-	int event;
-	try {
-		event = _reader.getEventType();
-	} catch (XmlPullParserException e) {
-		throw new ContentDecodingException(e.getMessage(), e);
-	}
-	if (event != XmlPullParser.END_DOCUMENT) {
-		throw new ContentDecodingException("Expected end document, got: " + XmlPullParser.TYPES[event]);
-	}
-};
-
-exports.prototype.readStartElement = function(/*String*/ startTag,
-							TreeMap<String, String> attributes) throws ContentDecodingException {
-
-	int event = readToNextTag(XmlPullParser.START_TAG);
-	if (event != XmlPullParser.START_TAG) {
-		throw new ContentDecodingException("Expected start element, got: " + XmlPullParser.TYPES[event]);
-	}
-	// Use getLocalPart to strip namespaces.
-	// Assumes we are working with a global default namespace of CCN.
-	if (!startTag.equals(_reader.getName())) {
-		// Coming back with namespace decoration doesn't match
-		throw new ContentDecodingException("Expected start element: " + startTag + " got: " + _reader.getName());
-	}	
-	if (null != attributes) {
-		// we might be expecting attributes
-		for (int i=0; i < _reader.getAttributeCount(); ++i) {
-			// may need fancier namespace handling.
-			attributes.put(_reader.getAttributeName(i), _reader.getAttributeValue(i));
-		}
-	}
-	try {
-		_reader.next();
-	} catch (XmlPullParserException e) {
-		throw new ContentDecodingException(e.getMessage());
-	} catch (IOException e) {
-		throw new ContentDecodingException(e.getMessage());
-	}
-}
-
-	public void readStartElement(long startTagLong,
-			TreeMap<String, String> attributes) throws ContentDecodingException {
-		
-		String startTag = tagToString(startTagLong);
-
-		int event = readToNextTag(XmlPullParser.START_TAG);
-		if (event != XmlPullParser.START_TAG) {
-			throw new ContentDecodingException("Expected start element, got: " + XmlPullParser.TYPES[event]);
-		}
-		// Use getLocalPart to strip namespaces.
-		// Assumes we are working with a global default namespace of CCN.
-		if (!startTag.equals(_reader.getName())) {
-			// Coming back with namespace decoration doesn't match
-			throw new ContentDecodingException("Expected start element: " + startTag + " got: " + _reader.getName());
-		}	
-		if (null != attributes) {
-			// we might be expecting attributes
-			for (int i=0; i < _reader.getAttributeCount(); ++i) {
-				// may need fancier namespace handling.
-				attributes.put(_reader.getAttributeName(i), _reader.getAttributeValue(i));
-			}
-		}
-		try {
-			_reader.next();
-		} catch (XmlPullParserException e) {
-			throw new ContentDecodingException(e.getMessage());
-		} catch (IOException e) {
-			throw new ContentDecodingException(e.getMessage());
-		}
-	}
-	public String peekStartElementAsString() throws ContentDecodingException {
-		int event = readToNextTag(XmlPullParser.START_TAG);
-		if (event != XmlPullParser.START_TAG) {
-			return null;
-		}
-		return _reader.getName();
-	}
-	
-	public Long peekStartElementAsLong() throws ContentDecodingException {
-		String strTag = peekStartElementAsString();
-		if (null == strTag) {
-			return null; // e.g. hit an end tag...
-		}
-		return stringToTag(strTag);
-	}
-	
-	/**
-	 * Helper method to decode text (UTF-8) and binary elements. Consumes the end element,
-	 * behavior which other decoders are forced to match.
-	 * @return the read data, as a String
-	 * @throws ContentDecodingException if there is a problem decoding the data
-	 */
-	public String readUString() throws ContentDecodingException {
-		StringBuffer buf = new StringBuffer();
-		try {
-			int event = _reader.getEventType();;
-			// Handles empty text element.
-			while (event == XmlPullParser.TEXT) {
-				buf.append(_reader.getText());
-				event = _reader.next();
-			}
-			if (event == XmlPullParser.START_TAG) {
-				throw new ContentDecodingException("readElementText expects start element to have been previously consumed, got: " + XmlPullParser.TYPES[event]);
-			} else if (event != XmlPullParser.END_TAG) {
-				throw new ContentDecodingException("Expected end of text element, got: " + XmlPullParser.TYPES[event]);
-			}
-			readEndElement();
-			return buf.toString();
-		} catch (XmlPullParserException e) {
-			throw new ContentDecodingException(e.getMessage(), e);
-		} catch (IOException e) {
-			throw new ContentDecodingException(e.getMessage(), e);
-		}
-	}
-
-	public void readEndElement() throws ContentDecodingException {
-		int event = readToNextTag(XmlPullParser.END_TAG);
-		if (event != XmlPullParser.END_TAG) {
-			throw new ContentDecodingException("Expected end element, got: " + XmlPullParser.TYPES[event]);
-		}
-		try {
-			_reader.next();
-		} catch (XmlPullParserException e) {
-			throw new ContentDecodingException(e.getMessage());
-		} catch (IOException e) {
-			throw new ContentDecodingException(e.getMessage());
-		}
-	}
-
-	/**
-	 * Read a BLOB. Consumes the end element, so force other versions
-	 * to match.
-	 */
-	public byte [] readBlob() throws ContentDecodingException {
-		try {
-			String strElementText = readUString();
-			// readEndElement(); // readElementText consumes end element
-			return TextXMLCodec.decodeBinaryElement(strElementText);
-		} catch (IOException e) {
-			throw new ContentDecodingException(e.getMessage(),e);
-		}
-	}
-	
-	public CCNTime readDateTime(String startTag) throws ContentDecodingException {
-		String strTimestamp = readUTF8Element(startTag);
-		CCNTime timestamp;
-		try {
-			timestamp = TextXMLCodec.parseDateTime(strTimestamp);
-		} catch (ParseException e) {
-			timestamp = null;
-		}
-		if (null == timestamp) {
-			throw new ContentDecodingException("Cannot parse timestamp: " + strTimestamp);
-		}		
-		return timestamp;
-	}
-
-	public CCNTime readDateTime(long startTag) throws ContentDecodingException {
-		String strTimestamp = readUTF8Element(startTag);
-		CCNTime timestamp;
-		try {
-			timestamp = TextXMLCodec.parseDateTime(strTimestamp);
-		} catch (ParseException e) {
-			timestamp = null;
-		}
-		if (null == timestamp) {
-			throw new ContentDecodingException("Cannot parse timestamp: " + strTimestamp);
-		}		
-		return timestamp;
-	}
-
-	private int readToNextTag(int type) throws ContentDecodingException {
-		int event;
-		try {
-			event = _reader.getEventType();
-			if (event == type)
-				return event;
-			if (event == XmlPullParser.TEXT || event == XmlPullParser.COMMENT)
-				event = _reader.next();
-		} catch (IOException e) {
-			throw new ContentDecodingException(e.getMessage(), e);
-		} catch (XmlPullParserException e) {
-			throw new ContentDecodingException(e.getMessage(), e);
-		}
-		return event;
-	}
-
-};
diff --git a/js/encoding/TextXMLEncoder.js b/js/encoding/TextXMLEncoder.js
index 495984b..2c8a828 100644
--- a/js/encoding/TextXMLEncoder.js
+++ b/js/encoding/TextXMLEncoder.js
@@ -17,93 +17,4 @@
 	this.ostream = new String();
 };
 
-exports.TextXMLEncoder = TextXMLEncoder;
 
-TextXMLEncoder.prototype.beginEncoding = function(/*OutputStream*/ ostream){
-		if (null == ostream)
-			throw new IllegalArgumentException("TextXMLEncoder: output stream cannot be null!");
-		
-		
-		/*Start by encoing the begining*/
-		//this.IStream = ostream;
-		this.ostream.write('<?xml version="1.0" encoding="UTF-8"?>');
-};
-
-TextXMLEncoder.prototype.endEncoding =function() {
-	this.IStream.end();
-}
-
-
-TextXMLEncoder.prorotype.writeStartElement(/*String*/ tag, /*TreeMap<String, String>*/ attributes) {
-		
-	
-		this.ostream.write('<'+tab);
-
-		if (null != attributes) {
-			
-			for(var i=0; i<attributes.length;i++){
-				this.ostream.write(' '+attributes[i].key +'='+attributes[i].value);
-			}
-		
-			// keySet of a TreeMap is ordered
-		}
-		this.ostream.write('>');
-};
-
-TextXMLEncoder.prototype.writeUString = function(/*String*/ utf8Content) {
-
-		this.ostream.write(utf8Content);
-
-};
-
-
-TextXMLEncoder.prototype.writeBlob =  function(/*byte []*/ binaryContent, /*int*/ offset, /*int*/ length) {
-
-		this.ostream.write(TextXMLCodec.encodeBinaryElement(binaryContent, offset, length));
-
-};
-
-TextXMLEncoder.prototype.writeElement = function(/*String*/ tag, /*byte[]*/ binaryContent,
-			/*TreeMap<String, String>*/ attributes)  {
-		
-		/*if (null == attributes) {
-		
-			attributes = new TreeMap<String,String>();
-		}*/
-		if (!attributes.containsKey(TextXMLCodec.BINARY_ATTRIBUTE)) {
-			attributes.put(TextXMLCodec.BINARY_ATTRIBUTE, TextXMLCodec.BINARY_ATTRIBUTE_VALUE);
-		}
-		super.writeElement(tag, binaryContent, attributes);
-}
-
-
-TextXMLEncoder.prototype.writeEndElement(tag) {
-
-		this.ostream.write('<'+tab+'>');
-
-	};
-
-	
-//returns number long
-stringToTag = function(/*String*/ tagName) {
-
-	if (null == tagName) {
-		return null;
-	}
-	Long tagVal = null;
-	if (null != _dictionaryStack) {
-		for (/*XMLDictionary*/ dictionary in _dictionaryStack) {
-			tagVal = dictionary.stringToTag(tagName);
-			if (null != tagVal) {
-				return tagVal;
-			}
-		}
-	}
-
-
-	if (XMLDictionaryStack.isUnknownTag(tagName)) {
-		return XMLDictionaryStack.decodeUnknownTag(tagName);
-	}
-	return null;
-};
-	
diff --git a/js/java_socket_bridge.js b/js/java_socket_bridge.js
index 3eccdfc..f2ee60d 100644
--- a/js/java_socket_bridge.js
+++ b/js/java_socket_bridge.js
@@ -3,12 +3,13 @@
  * This class represents Interest Objects

  */

 

-//var ccndAddr = unescape(%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F);

-var ccndAddrHex = '%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F';

 

-var LOG = 5;

+//var ccnxnodename = unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F');

 

-// Global variables

+

+var LOG = 0;

+

+

 var java_socket_bridge_ready_flag = false;

 

 var ndnport =null;

@@ -16,411 +17,74 @@
 

 var registeredPrefixes ={};

 

+/**

+ * Add a trim funnction for Strings

+ */

 String.prototype.trim = function() {

 	return this.replace(/^\s+|\s+$/g, "");

 };

 

+

 // Applet reports it is ready to use

 function java_socket_bridge_ready(){

+	console.log('APPLET LOADED');

 	java_socket_bridge_ready_flag = true;

-}

-

-

-

-

-//Sets the route to ccnx router

-/**

- * Setup the router to use

- * @url the url of the remote NDN router

- * @port the port of the remote NDN router

- */

-function createRoute(url, port){

-	ndnport = port;

-	ndnurl=url;

-	

-	console.log(new BinaryXMLDecoder());

-

-	//SEND INTERST TO CCNX NODE

-

-	

-	//Now Start the receiving thread

 	

 }

 

-// Connect to a given url and port

-//Error -1 No countent found

-//Error -2 Empty query

-function queryPrefix(message){

-	if(ndnport!=null && ndnurl!=null){

-		var newMessage ='';

 

 

-		message = message.trim();

-		

-

-		

-		if(message==null || message =="" || message=="/"){

-			return -2;

-		}

-		

-		//message = decodeURIComponent(message);

-		

-		var array = createNameArray(message);

-		

-		//console.log('ARRAY IS '+ array);

-		

-		enc = new BinaryXMLEncoder();

- 

-		int = new Interest(new ContentName(array));

-

-		int.encode(enc);

-		

-		var hex = toHex(enc.getReducedOstream());

-		

-		

-		

-		//console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);

-

-

-		var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);

-		

-		console.log('BINARY RESPONSE IS ' +result);

-		

-		

-		//result[0] and result[1] should be 0 and 4 if there is a content object found

-		if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){

-			return -1;

-		}

-		

-		else{

-			

-			var numbers = toNumbers(result);

-			

-			console.log('HEX RESPONSE IS \n'+numbers);

-			decoder = new BinaryXMLDecoder(numbers);

-			

-			

-			co = new ContentObject();

-        

-			co.decode(decoder);

-

-			if(LOG>2) console.log(co);

-

-			return co;

-			

-

-		}

-		

-

-	}

-

-

-	else{

-

-		alert('ERROR URL OR PORT NOT SET');

-

-		return -3;

-

-	}

-

-}

-

-var registerStarted = false;

-function registerPrefix(name, content){

-	

-	registeredPrefixes[name] = content ;

-	

-	if(registerStarted == false){

-		var result = get_java_socket_bridge().connectAndStartAndPublish();

-		

-		startRegisterPrefix();

-		

-		registerStarted = true;

-	}

-	sendForwardingEntry(10);

-}

-

-

-function unRegisterPrefix(name){

-	

-	delete registeredPrefixes[name];

-

-}

-

-

-

-

-function on_socket_received_interest(IP, port, interestBinary){

-	console.log('WOOOO RECEIVED STUFF' );

-	var interest = decodeHexInterest(interestBinary);

-	

-	console.log('WOOO received interest' + interest.Name.Components);

-	

-	var stringName = "";

-	

-	for(var i=0;i<interest.Name.Components.length;i++){

-		stringName += "/"+ interest.Name.Components[i];

-	}

-

-	if(registeredPrefix[stringName]!=null){

-		if(LOG>1)console.log("CANNOT FIND THE OBJECT OF NAME " + stringName );

+// Send Test Interest

+function get(host,port,data){

+	if(java_socket_bridge_ready_flag){

+		return get_java_socket_bridge().get(host,port,data,1000);

 	}

 	else{

-		var co = new ContentObject(interest.Name, null,registeredPrefix[stringName],null );

-		

-		var hex = encodeToHexContentObject(co);

-		

-		get_java_socket_bridge().sendContentObject(IP,port,hex);

-		

-		

+		on_socket_error("Java Socket Bridge send Interest until the applet has loaded");

 	}

 }

 

 

-

-

-// Connect to a given url and port

-//Error -1 No countent found

-//Error -2 Empty query

-function startRegisterPrefix(){

-	if(LOG>2) console.log('START REGISTER PREFIX');

+// Send Test Interest

+function put(host,port,data,name){

 	

-	if(ndnport!=null && ndnurl!=null){

-		var newMessage ='';

-		

-		

-

-		name = name.trim();

-		

-		

-

-		///////////////////////

-		var face = new FaceInstance('newface',null,null, 17, '127.0.0.1',9876,null,null,null);

-		

-		var encoder1 = new BinaryXMLEncoder();

-		 

-		face.encode(encoder1);

-

-		var faceInstanceBinary = encoder1.getReducedOstream();

-

-		

-		var si = new SignedInfo();

-		si.setFields();

-		

-		var co = new ContentObject(new ContentName(),si,faceInstanceBinary,new Signature()); 

-		co.sign();

-		

-		var encoder2 = new BinaryXMLEncoder();

-

-		co.encode(encoder2);

-

-		var coBinary = encoder2.getReducedOstream();

-		

-		//if(LOG>3)console.log('ADDESS OF CCND IS'+unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F'));

-		

-		//var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);

-		var interestName = new ContentName(['ccnx',unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F'),'newface',coBinary]);

-		//var interestName = new ContentName(['ccnx','%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F','newface',coBinary]);

-

-		//var interestName = new ContentName(['ccnx','1234','newface',coBinary]);

-		//var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);

-		int = new Interest(interestName,face);

-		

-		var hex = encodeToHexInterest(int);

-		/////////////////

-		

-		

-		

-		if(LOG>4)console.log('Interst name of Conntection Message is '+ interestName);

-		

-

-		if(LOG>4) console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+hex);

-		//console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);

-		

-		var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);

-

-		

-		//TODO MOVE THIS

-		

-		//result[0] and result[1] should be 0 and 4 if there is a content object found

-		if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){

-			return -1;

-		}

-		

-		if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);

-			

-		else{

-			

-			co = decodeHexContentObject(result);

-			

-			if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);

-			

-			return co;

-		}

+	if(java_socket_bridge_ready_flag){ 

+		return get_java_socket_bridge().put(host,port,data,name);

 	}

 	else{

-

-		alert('ERROR URL OR PORT NOT SET');

-

-		return -3;

-

-	}	

-

-}

-

-

-// Connect to a given url and port

-//Error -1 No countent found

-//Error -2 Empty query

-function sendForwardingEntry(faceID){

-	if(LOG>2) console.log('START REGISTER PREFIX');

-	

-	if(ndnport!=null && ndnurl!=null){

-		var newMessage ='';

-		

-		

-

-		name = name.trim();

-		

-		

-

-		///////////////////////

-		var face = new ForwardingEntry('prefixreg',new ContentName(['helloworld']),null, faceID, 1,null);

-		

-		var encoder1 = new BinaryXMLEncoder();

-		 

-		face.encode(encoder1);

-

-		var faceInstanceBinary = encoder1.getReducedOstream();

-

-		

-

-		var si = new SignedInfo();

-		si.setFields();

-		

-		var co = new ContentObject(new ContentName(),si,faceInstanceBinary,new Signature()); 

-		co.sign();

-		

-		var encoder2 = new BinaryXMLEncoder();

-

-		co.encode(encoder2);

-

-		var coBinary = encoder2.getReducedOstream();

-

-

-

-		var interestName = new ContentName(['ccnx',unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F'),'prefixreg',coBinary]);

-		//var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);

-		//var interestName = new ContentName(['ccnx','%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F','newface',coBinary]);

-

-		//var interestName = new ContentName(['ccnx','1234','newface',coBinary]);

-		//var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'prefixreg',coBinary]);

-

-		int = new Interest(interestName,face);

-		

-		var hex = encodeToHexInterest(int);

-		/////////////////

-

-

-		

-		if(LOG>4)console.log('Interst name of Conntection Message is '+ interestName);

-		

-

-		if(LOG>4) console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+hex);

-		//console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);

-		

-		var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);

-		

-		if(LOG>3)console.log('BINARY RESPONSE IS ' +result);

-		

-		

-		//result[0] and result[1] should be 0 and 4 if there is a content object found

-		if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){

-			return -1;

-		}

-		

-		if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);

-			

-		else{

-			

-			co = decodeHexContentObject(result);

-			

-			if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);

-			

-			return co;

-		}

+		on_socket_error("Java Socket Bridge send Interest until the applet has loaded");

 	}

-	else{

-

-		alert('ERROR URL OR PORT NOT SET');

-

-		return -3;

-

-	}	

-

 }

 

-

-

-

-function encodeToHexInterest(int){

+function on_socket_received_interest(hex,name){

 	

-	var enc = new BinaryXMLEncoder();

- 

-	int.encode(enc);

+	if(LOG>3)console.log('received interest from host'+ host +':'+port+' with name '+name);

 	

-	var hex = toHex(enc.getReducedOstream());

-

-	return hex;

-

+	if(LOG>3)console.log('DATA ');

 	

+	if(LOG>3)console.log(hex);

+	

+	interest = decodeHexInterest(hex);

+	

+	console.log('SUCCESSFULLY PARSED INTEREST');

+	

+	console.log('CREATING ANSWER');

+	var si = new SignedInfo();

+	si.setFields();

+	

+	var answer = toNumbersFromString('WORLD');

+

+	var co = new ContentObject(new ContentName(name),si,answer,new Signature()); 

+	co.sign();

+	

+	

+	var outputHex = encodeToHexContentObject(co);

+	

+	console.log('SENDING ANSWER');

+

+	return get_java_socket_bridge().putAnswer(outputHex,name);

 }

 

-

-function encodeToHexContentObject(co){

-	var enc = new BinaryXMLEncoder();

- 

-	co.encode(enc);

-	

-	var hex = toHex(enc.getReducedOstream());

-

-	return hex;

-

-	

-}

-

-function decodeHexInterest(result){

-	var numbers = toNumbers(result);

-			

-	

-	decoder = new BinaryXMLDecoder(numbers);

-	if(LOG>3)console.log('DECODED HEX INTERST  \n'+numbers);

-

-	i = new Interest();

-

-	i.decode(decoder);

-

-	return i;

-	

-}

-

-function decodeHexContentObject(result){

-	var numbers = toNumbers(result);

-

-	decoder = new BinaryXMLDecoder(numbers);

-	if(LOG>3)console.log('DECODED HEX CONTENT OBJECT \n'+numbers);

-	

-	co = new ContentObject();

-

-	co.decode(decoder);

-

-	return co;

-	

-}

-

-

-

-

 // Get something from the socket

 function on_socket_get(message){}

 

diff --git a/js/lwNDN.js b/js/lwNDN.js
new file mode 100644
index 0000000..cb9e8fc
--- /dev/null
+++ b/js/lwNDN.js
@@ -0,0 +1,114 @@
+
+
+var lwNDN = function lwNDN(host,port){
+	this.host = host;
+	this.port = port;
+};
+
+lwNDN.prototype.createRoute = function(host,port){
+	this.host=host;
+	this.port=port;
+}
+
+lwNDN.prototype.get = function(message){
+	if(this.host!=null && this.port!=null){
+		var output ='';
+		message = message.trim();
+		if(message==null || message =="" ){
+			console.log('INVALID INPUT TO GET');
+			return null;
+		}
+		
+		
+		//var array = ContentName.createNameArray(message);
+
+		int = new Interest(new ContentName(message));
+
+		int.InterestLifetime = 4200;
+		
+		var hex = encodeToHexInterest(int);
+		
+		//var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
+		
+		var result = get(this.host,this.port, hex);
+
+
+		if(LOG>0)console.log('BINARY RESPONSE IS ' +result);
+		
+		if(result==null || result==undefined || result =="" ){
+			/*if(result[0] != '0'||result[1]!='4') {
+				if(LOG>2)console.log('INVALID ANSWER');
+			}*/
+			return null;
+		}
+		
+		else{
+			
+			co = decodeHexContentObject(result);
+
+			if(LOG>2) {
+				console.log('DECODED CONTENT OBJECT');
+				console.log(co);
+			}
+			return co;
+		}
+	}
+	else{
+
+		console.log('ERROR URL OR PORT NOT SET');
+
+		return null;
+
+	}
+	
+
+}
+
+
+lwNDN.prototype.put = function(name,content){
+	if(this.host!=null && this.port!=null){
+		
+
+		name = name.trim();
+		
+		var fe = new ForwardingEntry('selfreg',new ContentName(name),null, null, 3,2147483647);
+		
+		var bytes = encodeForwardingEntry(fe);
+		
+		
+		var si = new SignedInfo();
+		si.setFields();
+		
+		var co = new ContentObject(new ContentName(),si,bytes,new Signature()); 
+		co.sign();
+		
+		var coBinary = encodeToBinaryContentObject(co);
+		
+		var ccnxnodename = unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F');
+		
+		var interestName = new ContentName(['ccnx',ccnxnodename,'prefixreg',coBinary]);
+
+		int = new Interest(interestName);
+		int.Scope = 1;
+		
+		var hex = encodeToHexInterest(int);
+
+		console.log('GOING TO PUT INTEREST OBJECT');
+		
+		console.log(hex);
+		
+		var result = put(this.host,this.port, hex,name);
+
+		return result;
+
+	}
+	else{
+
+		console.log('ERROR URL OR PORT NOT SET');
+
+		return null;
+
+	}
+	
+
+}
\ No newline at end of file
diff --git a/js/security/KeyManager.js b/js/security/KeyManager.js
index 7521c84..e2973e2 100644
--- a/js/security/KeyManager.js
+++ b/js/security/KeyManager.js
@@ -2,6 +2,36 @@
 
 var KeyManager = function KeyManager(){
 
+	
+//Certificate from CCNx
+
+this.certificate = 'MIIBmzCCAQQCCQC32FyQa61S7jANBgkqhkiG9w0BAQUFADASMRAwDgYDVQQDEwd'+
+
+'heGVsY2R2MB4XDTEyMDQyODIzNDQzN1oXDTEyMDUyODIzNDQzN1owEjEQMA4GA1'+
+
+'UEAxMHYXhlbGNkdjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA4X0wp9goq'+
+
+'xuECxdULcr2IHr9Ih4Iaypg0Wy39URIup8/CLzQmdsh3RYqd55hqonu5VTTpH3i'+
+
+'MLx6xZDVJAZ8OJi7pvXcQ2C4Re2kjL2c8SanI0RfDhlS1zJadfr1VhRPmpivcYa'+
+
+'wJ4aFuOLAi+qHFxtN7lhcGCgpW1OV60oXd58CAwEAATANBgkqhkiG9w0BAQUFAA'+
+
+'OBgQDLOrA1fXzSrpftUB5Ro6DigX1Bjkf7F5Bkd69hSVp+jYeJFBBlsILQAfSxU'+
+
+'ZPQtD+2Yc3iCmSYNyxqu9PcufDRJlnvB7PG29+L3y9lR37tetzUV9eTscJ7rdp8'+
+
+'Wt6AzpW32IJ/54yKNfP7S6ZIoIG+LP6EIxq6s8K1MXRt8uBJKw==';
+
+
+//this.publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDhfTCn2CirG4QLF1QtyvYgev0iHghrKmDRbLf1REi6nz8IvNCZ2yHdFip3nmGqie7lVNOkfeIwvHrFkNUkBnw4mLum9dxDYLhF7aSMvZzxJqcjRF8OGVLXMlp1+vVWFE+amK9xhrAnhoW44sCL6ocXG03uWFwYKClbU5XrShd3nwIDAQAB';
+this.publicKey ='30819F300D06092A864886F70D010101050003818D0030818902818100E17D30A7D828AB1B840B17542DCAF6207AFD221E086B2A60D16CB7F54448BA9F3F08BCD099DB21DD162A779E61AA89EEE554D3A47DE230BC7AC590D524067C3898BBA6F5DC4360B845EDA48CBD9CF126A723445F0E1952D7325A75FAF556144F9A98AF7186B0278685B8E2C08BEA87171B4DEE585C1828295B5395EB4A17779F0203010001';
+//Private Key from CCNx
+
+this.privateKey ='MIICXQIBAAKBgQDhfTCn2CirG4QLF1QtyvYgev0iHghrKmDRbLf1REi6nz8IvNCZ2yHdFip3nmGqie7lVNOkfeIwvHrFkNUkBnw4mLum9dxDYLhF7aSMvZzxJqcjRF8OGVLXMlp1+vVWFE+amK9xhrAnhoW44sCL6ocXG03uWFwYKClbU5XrShd3nwIDAQABAoGAGkv6T6jC3WmhFZYL6CdCWvlc6gysmKrhjarrLTxgavtFY6R5g2ft5BXAsCCVbUkWxkIFSKqxpVNl0gKZCNGEzPDN6mHJOQI/h0rlxNIHAuGfoAbCzALnqmyZivhJAPGijAyKuU9tczsst5+Kpn+bn7ehzHQuj7iwJonS5WbojqECQQD851K8TpW2GrRizNgG4dx6orZxAaon/Jnl8lS7soXhllQty7qG+oDfzznmdMsiznCqEABzHUUKOVGE9RWPN3aRAkEA5D/w9N55d0ibnChFJlc8cUAoaqH+w+U3oQP2Lb6AZHJpLptN4y4b/uf5d4wYU5/i/gC7SSBH3wFhh9bjRLUDLwJAVOx8vN0Kqt7myfKNbCo19jxjVSlA8TKCn1Oznl/BU1I+rC4oUaEW25DjmX6IpAR8kq7S59ThVSCQPjxqY/A08QJBAIRaF2zGPITQk3r/VumemCvLWiRK/yG0noc9dtibqHOWbCtcXtOm/xDWjq+lis2i3ssOvYrvrv0/HcDY+Dv1An0CQQCLJtMsfSg4kvG/FRY5UMhtMuwo8ovYcMXt4Xv/LWaMhndD67b2UGawQCRqr5ghRTABWdDD/HuuMBjrkPsX0861';
+
+
+/*
 	this.certificate = 
 			'MIIBvTCCASYCCQD55fNzc0WF7TANBgkqhkiG9w0BAQUFADAjMQswCQYDVQQGEwJK'+
 			'UDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwHhcNMTAwNTI4MDIwODUxWhcNMjAwNTI1'+
@@ -28,6 +58,8 @@
 			'aYZ5/5B2lwroqnKdZBJMGKFpUDn7Mb5hiSgocxnvMkv6NjT66Xsi3iYakJII9q8C'+
 			'Ma1qZvT/cigmdbAh7wJAQNXyoizuGEltiSaBXx4H29EdXNYWDJ9SS5f070BRbAIl'+
 			'dqRh3rcNvpY6BKJqFapda1DjdcncZECMizT/GMrc1w==';
+			
+			*/
 };
 
 
@@ -44,7 +76,6 @@
 	var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
 	
 	return result;
-	
 };
 
 KeyManager.prototype.sign= function sign(message){
@@ -54,6 +85,7 @@
 	var  _PEM_PRIVATE_KEY_STRING_ = this.privateKey;
 	
 	var rsa = new RSAKey();
+	
 	rsa.readPrivateKeyFromPEMString(_PEM_PRIVATE_KEY_STRING_);
 	
 	var hSig = rsa.signString(input, "sha256");
diff --git a/js/securityLib/rsa.js b/js/securityLib/rsa.js
index 6150003..11efe45 100644
--- a/js/securityLib/rsa.js
+++ b/js/securityLib/rsa.js
@@ -24,7 +24,11 @@
     return b.toString(16);

 }

 

-// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint

+/**

+ * PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint

+ * @param s: the string to encode

+ * @param n: the size in byte

+ */ 

 function pkcs1pad2(s,n) {

   if(n < s.length + 11) { // TODO: fix for utf-8

     alert("Message too long for RSA");

@@ -60,7 +64,10 @@
   return new BigInteger(ba);

 }

 

-// "empty" RSA key constructor

+/** 

+ * "empty" RSA key constructor

+ * @returns {RSAKey}

+ */

 function RSAKey() {

   this.n = null;

   this.e = 0;

@@ -72,7 +79,12 @@
   this.coeff = null;

 }

 

-// Set the public key fields N and e from hex strings

+/** 

+ * Set the public key fields N and e from hex strings

+ * @param N

+ * @param E

+ * @returns {RSASetPublic}

+ */

 function RSASetPublic(N,E) {

   if(N != null && E != null && N.length > 0 && E.length > 0) {

     this.n = parseBigInt(N,16);

@@ -82,12 +94,18 @@
     alert("Invalid RSA public key");

 }

 

-// Perform raw public operation on "x": return x^e (mod n)

+/** 

+ * Perform raw public operation on "x": return x^e (mod n)

+ * @param x

+ * @returns x^e (mod n)

+ */

 function RSADoPublic(x) {

   return x.modPowInt(this.e, this.n);

 }

 

-// Return the PKCS#1 RSA encryption of "text" as an even-length hex string

+/**

+ * Return the PKCS#1 RSA encryption of "text" as an even-length hex string

+ */ 

 function RSAEncrypt(text) {

   var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);

   if(m == null) return null;

diff --git a/js/securityLib/rsa2.js b/js/securityLib/rsa2.js
index e1f3f27..d75814e 100644
--- a/js/securityLib/rsa2.js
+++ b/js/securityLib/rsa2.js
@@ -57,7 +57,9 @@
     alert("Invalid RSA private key");

 }

 

-// Generate a new random private key B bits long, using public expt E

+/**

+ * Generate a new random private key B bits long, using public expt E

+ */

 function RSAGenerate(B,E) {

   var rng = new SecureRandom();

   var qs = B>>1;

@@ -91,7 +93,10 @@
   }

 }

 

-// Perform raw private operation on "x": return x^d (mod n)

+/**

+ * Perform raw private operation on "x": return x^d (mod n)

+ * @return x^d (mod n)

+ */ 

 function RSADoPrivate(x) {

   if(this.p == null || this.q == null)

     return x.modPow(this.d, this.n);

diff --git a/js/securityLib/rsasign-1.2.js b/js/securityLib/rsasign-1.2.js
index 645bf28..66cef59 100644
--- a/js/securityLib/rsasign-1.2.js
+++ b/js/securityLib/rsasign-1.2.js
@@ -56,6 +56,10 @@
 _RSASIGN_HASHHEXFUNC['md5'] =       function(s){return hex_md5(s);};   // http://pajhome.org.uk/crypt/md5/md5.html

 _RSASIGN_HASHHEXFUNC['ripemd160'] = function(s){return hex_rmd160(s);};   // http://pajhome.org.uk/crypt/md5/md5.html

 

+//@author axelcdv

+var _RSASIGN_HASHBYTEFUNC = [];

+_RSASIGN_HASHBYTEFUNC['sha256'] = 	function(byteArray){return hex_sha256_from_bytes(byteArray);};

+

 //_RSASIGN_HASHHEXFUNC['sha1'] =   function(s){return sha1.hex(s);}   // http://user1.matsumoto.ne.jp/~goma/js/hash.html

 //_RSASIGN_HASHHEXFUNC['sha256'] = function(s){return sha256.hex;}    // http://user1.matsumoto.ne.jp/~goma/js/hash.html

 

@@ -100,6 +104,29 @@
   return sPaddedMessageHex;

 }

 

+/**

+ * Apply padding, then computes the hash of the given byte array, according to the key size and with the hash algorithm

+ * @param byteArray (byte[])

+ * @param keySize (int)

+ * @param hashAlg the hash algorithm to apply (string)

+ * @return the hash of byteArray

+ */

+function _rsasign_getHexPaddedDigestInfoForByteArray(byteArray, keySize, hashAlg){

+	var pmStrLen = keySize / 4;

+	var hashFunc = _RSASIGN_HASHBYTEFUNC[hashAlg];

+	var sHashHex = hashFunc(byteArray); //returns hex hash

+	

+	var sHead = "0001";

+	  var sTail = "00" + _RSASIGN_DIHEAD[hashAlg] + sHashHex;

+	  var sMid = "";

+	  var fLen = pmStrLen - sHead.length - sTail.length;

+	  for (var i = 0; i < fLen; i += 2) {

+	    sMid += "ff";

+	  }

+	  sPaddedMessageHex = sHead + sMid + sTail;

+	  return sPaddedMessageHex;

+}

+

 function _zeroPaddingOfSignature(hex, bitLength) {

   var s = "";

   var nZero = bitLength / 4 - hex.length;

@@ -138,6 +165,34 @@
 }

 

 

+/**

+ * Sign a message byteArray with an RSA private key

+ * @name signByteArray

+ * @memberOf RSAKey#

+ * @function

+ * @param {byte[]} byteArray

+ * @param {Sring} hashAlg the hash algorithm to apply

+ * @param {RSAKey} rsa key to sign with: hack because the context is lost here

+ * @return hexadecimal string of signature value

+ */

+function _rsasign_signByteArray(byteArray, hashAlg, rsaKey) {

+	var hPM = _rsasign_getHexPaddedDigestInfoForByteArray(byteArray, rsaKey.n.bitLength(), hashAlg); ///hack because the context is lost here

+	var biPaddedMessage = parseBigInt(hPM, 16);

+	var biSign = rsaKey.doPrivate(biPaddedMessage); //hack because the context is lost here

+	var hexSign = biSign.toString(16);

+	return _zeroPaddingOfSignature(hexSign, rsaKey.n.bitLength()); //hack because the context is lost here

+}

+

+/**

+ * Sign a byte array with the Sha-256 algorithm

+ * @param {byte[]} byteArray

+ * @return hexadecimal string of signature value

+ */

+function _rsasign_signByteArrayWithSHA256(byteArray){

+	return _rsasign_signByteArray(byteArray, 'sha256', this); //Hack because the context is lost in the next function

+}

+

+

 function _rsasign_signStringWithSHA1(s) {

   return _rsasign_signString(s, 'sha1');

 }

@@ -225,8 +280,42 @@
   return (diHashValue == msgHashValue);

 }

 

+/**

+ * verifies a sigature for a message byte array with RSA public key.<br/>

+ * @name verifyByteArray

+ * @memberOf RSAKey#

+ * @function

+ * @param {byte[]} byteArray message byte array to be verified.

+ * @param {String} hSig hexadecimal string of signature.<br/>

+ *                 non-hexadecimal charactors including new lines will be ignored.

+ * @return returns 1 if valid, otherwise 0 

+ */

+function _rsasign_verifyByteArray(byteArray, hSig) {

+	hSig = hSig.replace(_RE_HEXDECONLY, '');

+	  

+	  if(LOG>3)console.log('n is '+this.n);

+	  if(LOG>3)console.log('e is '+this.e);

+	  

+	  if (hSig.length != this.n.bitLength() / 4) return 0;

+	  hSig = hSig.replace(/[ \n]+/g, "");

+	  var biSig = parseBigInt(hSig, 16);

+	  var biDecryptedSig = this.doPublic(biSig);

+	  var hDigestInfo = biDecryptedSig.toString(16).replace(/^1f+00/, '');

+	  var digestInfoAry = _rsasign_getAlgNameAndHashFromHexDisgestInfo(hDigestInfo);

+	  

+	  if (digestInfoAry.length == 0) return false;

+	  var algName = digestInfoAry[0];

+	  var diHashValue = digestInfoAry[1];

+	  var ff = _RSASIGN_HASHBYTEFUNC[algName];

+	  var msgHashValue = ff(byteArray);

+	  return (diHashValue == msgHashValue);

+}

+

 RSAKey.prototype.signString = _rsasign_signString;

 

+RSAKey.prototype.signByteArray = _rsasign_signByteArray; //@author axelcdv

+RSAKey.prototype.signByteArrayWithSHA256 = _rsasign_signByteArrayWithSHA256; //@author axelcdv

+

 RSAKey.prototype.signStringWithSHA1 = _rsasign_signStringWithSHA1;

 RSAKey.prototype.signStringWithSHA256 = _rsasign_signStringWithSHA256;

 RSAKey.prototype.sign = _rsasign_signString;

@@ -242,7 +331,7 @@
 RSAKey.prototype.signWithSHA256HEX = _rsasign_signStringWithSHA256HEX;

 */

 

-

+RSAKey.prototype.verifyByteArray = _rsasign_verifyByteArray;

 RSAKey.prototype.verifyString = _rsasign_verifyString;

 RSAKey.prototype.verifyHexSignatureForMessage = _rsasign_verifyHexSignatureForMessage;

 RSAKey.prototype.verify = _rsasign_verifyString;

diff --git a/js/securityLib/sha1.js b/js/securityLib/sha1.js
index eb380c9..0e5b5b7 100644
--- a/js/securityLib/sha1.js
+++ b/js/securityLib/sha1.js
@@ -14,7 +14,7 @@
 var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */

 var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */

 

-/*

+/**

  * These are the functions you'll usually want to call

  * They take string arguments and return either hex or base-64 encoded strings

  */

@@ -28,7 +28,7 @@
 function any_hmac_sha1(k, d, e)

   { return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }

 

-/*

+/**

  * Perform a simple self-test to see if the VM is working

  */

 function sha1_vm_test()

@@ -36,7 +36,7 @@
   return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";

 }

 

-/*

+/**

  * Calculate the SHA1 of a raw string

  */

 function rstr_sha1(s)

@@ -44,7 +44,7 @@
   return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));

 }

 

-/*

+/**

  * Calculate the HMAC-SHA1 of a key and some data (raw strings)

  */

 function rstr_hmac_sha1(key, data)

@@ -63,7 +63,7 @@
   return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));

 }

 

-/*

+/**

  * Convert a raw string to a hex string

  */

 function rstr2hex(input)

@@ -81,7 +81,7 @@
   return output;

 }

 

-/*

+/**

  * Convert a raw string to a base-64 string

  */

 function rstr2b64(input)

@@ -104,7 +104,7 @@
   return output;

 }

 

-/*

+/**

  * Convert a raw string to an arbitrary string encoding

  */

 function rstr2any(input, encoding)

@@ -149,14 +149,14 @@
 

   /* Append leading zero equivalents */

   var full_length = Math.ceil(input.length * 8 /

-                                    (Math.log(encoding.length) / Math.log(2)))

+                                    (Math.log(encoding.length) / Math.log(2)));

   for(i = output.length; i < full_length; i++)

     output = encoding[0] + output;

 

   return output;

 }

 

-/*

+/**

  * Encode a string as utf-8.

  * For efficiency, this assumes the input is valid utf-16.

  */

@@ -196,7 +196,7 @@
   return output;

 }

 

-/*

+/**

  * Encode a string as utf-16

  */

 function str2rstr_utf16le(input)

@@ -217,7 +217,7 @@
   return output;

 }

 

-/*

+/**

  * Convert a raw string to an array of big-endian words

  * Characters >255 have their high-byte silently ignored.

  */

@@ -231,7 +231,7 @@
   return output;

 }

 

-/*

+/**

  * Convert an array of big-endian words to a string

  */

 function binb2rstr(input)

@@ -242,7 +242,7 @@
   return output;

 }

 

-/*

+/**

  * Calculate the SHA-1 of an array of big-endian words, and a bit length

  */

 function binb_sha1(x, len)

@@ -289,7 +289,7 @@
 

 }

 

-/*

+/**

  * Perform the appropriate triplet combination function for the current

  * iteration

  */

@@ -301,7 +301,7 @@
   return b ^ c ^ d;

 }

 

-/*

+/**

  * Determine the appropriate additive constant for the current iteration

  */

 function sha1_kt(t)

@@ -310,7 +310,7 @@
          (t < 60) ? -1894007588 : -899497514;

 }

 

-/*

+/**

  * Add integers, wrapping at 2^32. This uses 16-bit operations internally

  * to work around bugs in some JS interpreters.

  */

@@ -321,7 +321,7 @@
   return (msw << 16) | (lsw & 0xFFFF);

 }

 

-/*

+/**

  * Bitwise rotate a 32-bit number to the left.

  */

 function bit_rol(num, cnt)

diff --git a/js/securityLib/sha256.js b/js/securityLib/sha256.js
index b3b38da..45f3cb3 100644
--- a/js/securityLib/sha256.js
+++ b/js/securityLib/sha256.js
@@ -20,6 +20,15 @@
  * They take string arguments and return either hex or base-64 encoded strings

  */

 

+//@author axelcdv

+/**

+ * Computes the Sha-256 hash of the given byte array

+ * @param {byte[]} 

+ * @return the hex string corresponding to the Sha-256 hash of the byte array

+ */

+function hex_sha256_from_bytes(byteArray){

+	return rstr2hex(binb2rstr(binb_sha256( byteArray2binb(byteArray), byteArray.length * 8)));

+}

 

 function hex_sha256(s)    { return rstr2hex(rstr_sha256(str2rstr_utf8(s))); }

 function b64_sha256(s)    { return rstr2b64(rstr_sha256(str2rstr_utf8(s))); }

@@ -53,15 +62,16 @@
             "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";

 }

 

-/*

+/**

  * Calculate the sha256 of a raw string

+ * @param s: the raw string

  */

 function rstr_sha256(s)

 {

   return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8));

 }

 

-/*

+/**

  * Calculate the HMAC-sha256 of a key and some data (raw strings)

  */

 function rstr_hmac_sha256(key, data)

@@ -80,7 +90,7 @@
   return binb2rstr(binb_sha256(opad.concat(hash), 512 + 256));

 }

 

-/*

+/**

  * Convert a raw string to a hex string

  */

 function rstr2hex(input)

@@ -234,7 +244,7 @@
   return output;

 }

 

-/*

+/**

  * Convert a raw string to an array of big-endian words

  * Characters >255 have their high-byte silently ignored.

  */

@@ -249,6 +259,22 @@
   return output;

 }

 

+/**

+ * @author axelcdv

+ * Convert a byte array to an array of big-endian words

+ * @param {byte[]} input

+ * @return the array of big-endian words

+ */

+function byteArray2binb(input){

+	console.log("Byte array coming is " + input);

+	var output = Array(input.length >> 2);

+	  for(var i = 0; i < output.length; i++)

+	    output[i] = 0;

+	  for(var i = 0; i < input.length * 8; i += 8)

+	    output[i>>5] |= (input[i / 8] & 0xFF) << (24 - i % 32);

+	  return output;

+}

+

 /*

  * Convert an array of big-endian words to a string

  */

diff --git a/js/test-connection.html b/js/test-connection.html
new file mode 100644
index 0000000..1b2f069
--- /dev/null
+++ b/js/test-connection.html
@@ -0,0 +1,123 @@
+<?xml version = "1.0" encoding="utf-8" ?>

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

+"DTD/xhtml1-strict.dtd">

+<html xmlns = "http://www.w3.org/1999/xhtml">

+

+<head>

+	<title>Test Connect </title>

+	<script type="text/javascript" src="java_socket_bridge.js"></script>

+	

+	<script type="text/javascript" src="CCNProtocolDTags.js"></script>

+	

+	<script type="text/javascript" src="CCNTime.js"></script>

+	

+	<script type="text/javascript" src="ContentName.js"></script>

+	

+	<script type="text/javascript" src="ContentObject.js"></script>

+	

+	<script type="text/javascript" src="DateFormat.js"></script>

+	

+	<script type="text/javascript" src="Exclude.js"></script>

+

+	<script type="text/javascript" src="ExcludeAny.js"></script>

+

+	<script type="text/javascript" src="ExcludeComponent.js"></script>

+

+	<script type="text/javascript" src="Interest.js"></script>

+	

+	<script type="text/javascript" src="KeyLocator.js"></script>

+	

+	<script type="text/javascript" src="KeyName.js"></script>

+

+	<script type="text/javascript" src="PublisherID.js"></script>

+	

+	<script type="text/javascript" src="Signature.js"></script>

+	

+	<script type="text/javascript" src="SignedInfo.js"></script>

+	

+	<script type="text/javascript" src="PublisherPublicKeyDigest.js"></script>

+	

+	<script type="text/javascript" src="FaceInstance.js"></script>

+	

+	<script type="text/javascript" src="ForwardingEntry.js"></script>

+	

+	

+	<script type="text/javascript" src="encoding/BinaryXMLEncoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLCodec.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLDecoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/DataUtils.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script>

+

+	<script type="text/javascript">

+

+		function getAction(){

+			console.log('ABOUT TO GET');

+

+

+			var received = get('127.0.0.1',9695,'01d2f2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b4559000002d28e310000');	

+

+			output= '<br /> received Content '+received;

+			

+			console.log('INTEREST RECEIVED '+ received);

+			

+			document.getElementById('result').innerHTML = output;

+		

+		}

+

+

+		function putAction(){

+			console.log('ABOUT TO PUT');

+

+			//var received = DataUtils.toString( DataUtils.toNumbers(send_test_interest()));

+			

+			var received = put('127.0.0.1',9695,'01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabd73656c6672656700fa1bf5048202aa03b208854a18988c72aee624da28e2e1acbccb209b8e89429041985521ed68f95a1c546872fba3d854b1377dc249b6d8ec5935e5069256c97a7f6d8a62e86222ccd2cfe5097aed3fe5ede6732ce191a8680d78e39d0c5058a2b7bb0f0687994e9f045de346b66c46498547a08da1f2f0cdfafba3afdfe7107931935ede79040137ba94a90000f20001a203e202851a4860caa4991e829bcdc9429fb711d52440968d23560726606050bf147acffc0002bab504fcb3f03aa40001e201da0a9530819f300d06092a864886f70d010101050003818d00308189028181008ed27580e3d1c4c67672208665133a1ba12d8ebf5cad8e054571926b3ff0782a04c71703384021a6cefb6616b66cbd8a679b761d69d6373a851546e26f7105510b4c23be9a3c7f2e652e100ecc1471855730659f1477ce4e8504ad1fd8f44116baaeae2ff67eec33abba790157a79bf5039e5a528a471d9d67c94e70117ed7490203010001000000019a0585058a04cabe73656c6672656700f2faad726f63636f000003e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004fa8e330003d2d63231343734383336343700000000000002d28e310000');	

+

+			output= '<br /> received Content '+received;

+						

+			document.getElementById('result').innerHTML = output;

+		

+		}

+		

+

+		</script>

+	

+</head>

+<body >

+	

+	<form>

+		Press Buttons:<br /><!--  input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" /--> <br />

+	</form>

+	

+	<button onclick="putAction()">PUT!</button>

+	<button onclick="getAction()">GET!</button>

+

+	<div >

+		<applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">

+		</applet>

+	</div>

+

+		<p id="result"></p>

+

+</body>

+</html>
\ No newline at end of file
diff --git a/js/test-decode-FaceInstance.html b/js/test-decode-FaceInstance.html
new file mode 100644
index 0000000..5ec30dd
--- /dev/null
+++ b/js/test-decode-FaceInstance.html
@@ -0,0 +1,167 @@
+<?xml version = "1.0" encoding="utf-8" ?>

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

+"DTD/xhtml1-strict.dtd">

+<html xmlns = "http://www.w3.org/1999/xhtml">

+

+<head>

+	<title>NDN Decode Face Instance</title>

+	

+	<script type="text/javascript" src="java_socket_bridge.js"></script>

+	

+	<script type="text/javascript" src="CCNProtocolDTags.js"></script>

+	

+	<script type="text/javascript" src="CCNTime.js"></script>

+	

+	<script type="text/javascript" src="ContentName.js"></script>

+	

+	<script type="text/javascript" src="ContentObject.js"></script>

+	

+	<script type="text/javascript" src="DateFormat.js"></script>

+	

+	<script type="text/javascript" src="Exclude.js"></script>

+

+	<script type="text/javascript" src="ExcludeAny.js"></script>

+

+	<script type="text/javascript" src="ExcludeComponent.js"></script>

+

+	<script type="text/javascript" src="Interest.js"></script>

+	

+	<script type="text/javascript" src="KeyLocator.js"></script>

+	

+	<script type="text/javascript" src="KeyName.js"></script>

+

+	<script type="text/javascript" src="PublisherID.js"></script>

+	

+	<script type="text/javascript" src="Signature.js"></script>

+	

+	<script type="text/javascript" src="SignedInfo.js"></script>

+	

+	<script type="text/javascript" src="PublisherPublicKeyDigest.js"></script>

+	

+	<script type="text/javascript" src="FaceInstance.js"></script>

+

+	<script type="text/javascript" src="ForwardingEntry.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLEncoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLCodec.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLDecoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/DataUtils.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script>

+

+	<script type="text/javascript">

+

+		function decode(){

+

+			var input = document.getElementById('result').innerHTML;

+

+			

+			var faceInstance = decodeHexFaceInstance(input);

+			

+			if(LOG>3)console.log('FACE INSTANCE DECODED');

+			if(LOG>3)console.log(faceInstance);

+

+			///////////////////////////////////////

+			

+			var output ="";

+			

+			if(faceInstance.PublisherPublicKeyDigest!=null ){

+				output+= "PublisherPublicKeyDigest: ";

+				

+					output+=  DataUtils.toHex(faceInstance.PublisherPublicKeyDigest.PublisherPublicKeyDigest);

+					

+					//output+= "PUBLISHER ID TYPE: ";

+					//output+=  faceInstance.PublisherPublicKeyDigest.PublisherPublicKeyDigest;

+					

+				output+= "<br />";

+				output+= "<br />";

+

+			}

+			

+			if(faceInstance.FaceID!=null){

+				output+= "FaceID: ";

+				

+				output+= faceInstance.FaceID;

+				output+= "<br />";

+			}

+			

+			if(faceInstance.IPProto!=null){

+				output+= "IPProto: ";

+				

+				output+= faceInstance.IPProto;

+				output+= "<br />";

+			}

+			

+			if(faceInstance.Host!=null){

+				output+= "Host: ";

+				

+				output+= faceInstance.Host;

+				output+= "<br />";

+			}

+			

+			if(faceInstance.Port!=null){

+				output+= "Port: ";

+				

+				output+= faceInstance.Port;

+				output+= "<br />";

+			}

+			if(faceInstance.FreshnessSeconds!=null){

+				output+= "FreshnessSeconds: ";

+				

+				output+= faceInstance.FreshnessSeconds;

+				output+= "<br />";

+			}

+			

+			/*if(interest.Name!=null && interest.Name.Components!=null){

+				output+= "NAME: ";

+				

+				for(var i=0;i<interest.Name.Components.length;i++){

+					output+= "/"+ DataUtils.toString(interest.Name.Components[i]);

+				}

+				output+= "<br />";

+				output+= "<br />";

+			}*/

+	

+			document.getElementById('result').innerHTML = output;

+			

+		}

+

+	</script>

+

+</head>

+<body >

+	<form>

+		

+		Please Enter a Interest:<br />

+		

+		<!--  input id="faceInstance" type="text" name="FACEINSTANCE" value="/PARC/abc" /--> 

+		

+	</form>

+	<button onclick="decode()">Decode</button>

+	

+	

+

+		<p id="result">058203e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004d29632310004da9631370004e2c631302e312e312e310004eaa6393639350003d2d6323134373438333634370000</p>

+

+</body>

+</html>
\ No newline at end of file
diff --git a/js/test-decode-Interest+Forwarding+Entry.html b/js/test-decode-Interest+Forwarding+Entry.html
new file mode 100644
index 0000000..6910e7c
--- /dev/null
+++ b/js/test-decode-Interest+Forwarding+Entry.html
@@ -0,0 +1,486 @@
+<?xml version = "1.0" encoding="utf-8" ?>

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

+"DTD/xhtml1-strict.dtd">

+<html xmlns = "http://www.w3.org/1999/xhtml">

+

+<head>

+	<title>NDN Decode Interest + Face Instance</title>

+	

+	<script type="text/javascript" src="java_socket_bridge.js"></script>

+	

+	<script type="text/javascript" src="CCNProtocolDTags.js"></script>

+	

+	<script type="text/javascript" src="CCNTime.js"></script>

+	

+	<script type="text/javascript" src="ContentName.js"></script>

+	

+	<script type="text/javascript" src="ContentObject.js"></script>

+	

+	<script type="text/javascript" src="DateFormat.js"></script>

+	

+	<script type="text/javascript" src="Exclude.js"></script>

+

+	<script type="text/javascript" src="ExcludeAny.js"></script>

+

+	<script type="text/javascript" src="ExcludeComponent.js"></script>

+

+	<script type="text/javascript" src="Interest.js"></script>

+	

+	<script type="text/javascript" src="KeyLocator.js"></script>

+	

+	<script type="text/javascript" src="KeyName.js"></script>

+

+	<script type="text/javascript" src="PublisherID.js"></script>

+	

+	<script type="text/javascript" src="Signature.js"></script>

+	

+	<script type="text/javascript" src="SignedInfo.js"></script>

+	

+	<script type="text/javascript" src="PublisherPublicKeyDigest.js"></script>

+	

+	<script type="text/javascript" src="FaceInstance.js"></script>

+

+	<script type="text/javascript" src="ForwardingEntry.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLEncoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLCodec.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLDecoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/DataUtils.js"></script>

+	

+	<script type="text/javascript" src="encoding/EncodingUtils.js"></script>

+	

+	

+	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script>

+

+	<script type="text/javascript">

+	

+

+		

+		function decode(){

+			

+

+			var input = document.getElementById('result').innerHTML;

+

+			

+			var interest = decodeHexInterest(input);

+			

+			if(LOG>3)console.log('INTEREST DECODED');

+			if(LOG>3)console.log(interest);

+

+			///////////////////////////////////////

+			

+			var output ="";

+			

+			

+			if(interest.Name!=null && interest.Name.Components!=null){

+				output+= "NAME: ";

+				

+				for(var i=0;i<interest.Name.Components.length;i++){

+					output+= "/"+ DataUtils.toString(interest.Name.Components[i]);

+				}

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.FaceInstance!=null ){

+				output+= "FaceInstance: ";

+				

+					output+=  interest.FaceInstance;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.Exclude!=null ){

+				output+= "Exclude: ";

+				

+					output+=  interest.Exclude;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.ChildSelector!=null ){

+				output+= "ChildSelector: ";

+				

+					output+=  interest.ChildSelector;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.AnswerOriginKind!=null ){

+				output+= "AnswerOriginKind: ";

+				

+					output+=  interest.AnswerOriginKind;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.InterestLifetime!=null ){

+				output+= "InterestLifetime: ";

+				

+					output+=  interest.InterestLifetime;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.Nonce!=null ){

+				output+= "Nonce: ";

+				

+					output+=  interest.Nonce;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			

+			if(interest.Scope!=null ){

+				output+= "SCOPE: ";

+				

+					output+=  interest.Scope;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+	

+			if(interest.PublisherID!=null ){

+				output+= "PUBLISHER ID: ";

+				

+					output+=  interest.PublisherID.PublisherID;

+					

+					output+= "PUBLISHER ID TYPE: ";

+					output+=  interest.PublisherID.PublisherType;

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.MaxSuffixComponents!=null ){

+				output+= "MaxSuffixComponents : ";

+				

+				output+=  interest.MaxSuffixComponents;

+

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.MinSuffixComponents!=null ){

+				output+= "MinSuffixComponents : ";

+				

+				output+=  interest.MinSuffixComponents;

+

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.MinSuffixComponents!=null ){

+				output+= "MinSuffixComponents : ";

+				

+				output+=  interest.MinSuffixComponents;

+

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.Name.Components[3] !=null){

+				

+				

+				var input = DataUtils.toHex(interest.Name.Components[3]) ;

+

+				var contentObject = decodeHexContentObject(input);

+				

+				if(contentObject.Content!=null ){

+					output+= "Content of content Object: ";

+					

+						output+=  DataUtils.toHex(contentObject.Content);

+						

+					output+= "<br />";

+					output+= "<br />";

+				}

+				

+				

+				var content = DataUtils.toHex(contentObject.Content);

+				

+				var co = contentObject;

+				

+				

+				////////////////////////////////////////

+				

+

+				if(co.Name!=null && co.Name.Components!=null){

+					output+= "NAME: ";

+					

+					for(var i=0;i<co.Name.Components.length;i++){

+						output+= "/"+ DataUtils.toString(co.Name.Components[i]);

+					}

+					output+= "<br />";

+					output+= "<br />";

+				}

+	

+				if(co.Content !=null){

+					output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);

+					

+					output+= "<br />";

+					output+= "<br />";

+				}

+				if(co.Content !=null){

+					output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);

+					

+					output+= "<br />";

+					output+= "<br />";

+				}

+				if(co.Signature !=null && co.Signature.Signature!=null){

+					

+					output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);

+					

+					output+= "<br />";

+					output+= "<br />";

+				}

+				if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){

+					

+					output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

+					

+					output+= "<br />";

+					output+= "<br />";

+				}

+				if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){

+					var d = new Date();

+					d.setTime( co.SignedInfo.Timestamp.msec );

+					

+					var bytes = [217, 185, 12, 225, 217, 185, 12, 225];

+					

+					output += "TimeStamp: "+d;

+					output+= "<br />";

+					output += "TimeStamp(number): "+ co.SignedInfo.Timestamp.msec;

+					

+					

+					output+= "<br />";

+				}

+			    if(co.SignedInfo !=null && co.SignedInfo.Type!=null){

+

+					output += "Type: "+co.SignedInfo.Type;

+					output+= "<br />";

+					output+= "<br />";

+				}

+			    if(co.SignedInfo !=null && co.SignedInfo.Locator!=null){

+

+					output += "Locator: "+co.SignedInfo.Locator.Type;

+					output+= "<br />";

+					output+= "<br />";

+				}

+			    if(co.SignedInfo !=null && co.SignedInfo.FreshnessSeconds!=null){

+

+					output += "FreshnessSeconds: "+co.SignedInfo.FreshnessSeconds;

+					output+= "<br />";

+					output+= "<br />";

+				}

+			    if(co.SignedInfo !=null && co.SignedInfo.FinalBlockID!=null){

+

+					output += "FinalBlockID: "+co.SignedInfo.FinalBlockID;

+					output+= "<br />";

+					output+= "<br />";

+				}

+				

+				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

+					

+					var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));

+					var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

+					var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);

+					

+					var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();

+					

+					

+					var input = DataUtils.toString(co.rawSignatureData);

+					 

+					

+					output += "DER Certificate: "+publickey ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					

+

+					if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

+					if(LOG>2) console.log(" PublicKey = "+publickey );

+					if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

+					if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

+					

+					if(LOG>2) console.log(" Signature "+signature );

+					

+					if(LOG>2) console.log(" Signature NOW IS" );

+					

+					if(LOG>2) console.log(co.Signature.Signature);

+					

+					

+					/*var x509 = new X509();

+					

+					x509.readCertPEM(publickey);

+					

+					

+					//x509.readCertPEMWithoutRSAInit(publickey);

+

+					var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/

+					//console.log('result is '+result);

+					

+					

+					var kp = publickeyHex.slice(56,314);

+					

+					output += "PUBLISHER KEY(hex): "+kp ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					console.log('PUBLIC KEY IN HEX is ');

+					console.log(kp);

+

+					var exp = publickeyHex.slice(318,324);

+					

+					console.log('kp size is '+kp.length );

+					output += "exponent: "+exp ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					console.log('EXPONENT is ');

+					console.log(exp);

+

+					

+					

+					/*var c1 = hex_sha256(input);

+					var c2 = signature;

+					

+					if(LOG>4)console.log('input is ');

+					if(LOG>4)console.log(input);

+					if(LOG>4)console.log('C1 is ');

+					if(LOG>4)console.log(c1);

+					if(LOG>4)console.log('C2 is ');

+					if(LOG>4)console.log(c2);

+					var result = c1 == c2;*/

+					

+					var rsakey = new RSAKey();

+					

+					rsakey.setPublic(kp,exp);

+					

+				    var result = rsakey.verifyString(input, signature);

+					

+				    

+				    

+				    console.log('PUBLIC KEY n after is ');

+					console.log(rsakey.n);

+

+					console.log('EXPONENT e after is ');

+					console.log(rsakey.e);

+					

+					

+					if(result)

+						output += 'SIGNATURE VALID';

+					else

+						output += 'SIGNATURE INVALID';

+

+					//output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					

+				    //if(LOG>4) console.log('str'[1]);

+				}

+				

+				////////////////////////////////////////

+				

+				

+				var forwardingEntry = decodeHexForwardingEntry(content);

+				

+				if(LOG>3)console.log('FORWARDING ENTRY IS PRESENT');

+				if(LOG>3)console.log(forwardingEntry);

+

+				///////////////////////////////////////

+				

+				//var output ="";

+				

+				if(forwardingEntry.Action!=null ){

+					output+= "Action: ";

+					

+					output+=  DataUtils.toHex(forwardingEntry.Action);

+						

+					output+= "<br />";

+					output+= "<br />";

+				}

+				

+				if(forwardingEntry.PrefixName!=null){

+					output+= "PrefixName: ";

+					

+					output+= forwardingEntry.PrefixName.getName();

+					output+= "<br />";

+				}

+				

+				if(forwardingEntry.CCNID!=null){

+					output+= "CCNID: ";

+					

+					output+= forwardingEntry.CCNID;

+					output+= "<br />";

+				}

+				

+				if(forwardingEntry.Flags!=null){

+					output+= "Flags: ";

+					

+					output+= forwardingEntry.Flags;

+					output+= "<br />";

+				}

+				

+				if(forwardingEntry.Lifetime!=null){

+					output+= "Lifetime: ";

+					

+					output+= forwardingEntry.Lifetime;

+					output+= "<br />";

+				}

+

+				

+			}

+			

+			

+			

+			document.getElementById('result').innerHTML = output;

+			

+		}

+

+	</script>

+

+</head>

+<body >

+	<form>

+		

+		Please Press decode:<br />

+		

+

+	</form>

+	<button onclick="decode()">Decode</button>

+

+		<!-- p id="result-old-from-ccnx">01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabd73656c6672656700fa1bf5048202aa03b208854a18988c72aee624da28e2e1acbccb209b8e89429041985521ed68f95a1c546872fba3d854b1377dc249b6d8ec5935e5069256c97a7f6d8a62e86222ccd2cfe5097aed3fe5ede6732ce191a8680d78e39d0c5058a2b7bb0f0687994e9f045de346b66c46498547a08da1f2f0cdfafba3afdfe7107931935ede79040137ba94a90000f20001a203e202851a4860caa4991e829bcdc9429fb711d52440968d23560726606050bf147acffc0002bab504fcb3f03aa40001e201da0a9530819f300d06092a864886f70d010101050003818d00308189028181008ed27580e3d1c4c67672208665133a1ba12d8ebf5cad8e054571926b3ff0782a04c71703384021a6cefb6616b66cbd8a679b761d69d6373a851546e26f7105510b4c23be9a3c7f2e652e100ecc1471855730659f1477ce4e8504ad1fd8f44116baaeae2ff67eec33abba790157a79bf5039e5a528a471d9d67c94e70117ed7490203010001000000019a0585058a04cabe73656c6672656700f2faad726f63636f000003e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004fa8e330003d2d63231343734383336343700000000000002d28e310000</p-->

+		

+		<p id="result">01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00facd70726566697872656700fa29ad048202aa03b208854ddbf69779cdf4ef74be99474478c8bc3ca0873e0ffa1fa60120aa276db122b83404e595a8a3caeaf09630276658ba4e7beaadb4b91a8cc58e19ac4a42289507ed8d609aa9bef61a5a507f349c83d2944b8c16fecfd90d4a40ddb8687592c0a57517564235b2e359db54f51a37e1ac39e518a2196e3ffda7eb2fb301f3c404dd0000f20001a203e20285ef7c4f5d4743a8b8586ea2e741b7fc39d1dc0dbe1b1930e787cfd1d833ea7a610002bab504fce9e253d70001e2018219fd3082019b30820104020900b7d85c906bad52ee300d06092a864886f70d010105050030123110300e060355040313076178656c636476301e170d3132303432383233343433375a170d3132303532383233343433375a30123110300e060355040313076178656c63647630819f300d06092a864886f70d010101050003818d0030818902818100e17d30a7d828ab1b840b17542dcaf6207afd221e086b2a60d16cb7f54448ba9f3f08bcd099db21dd162a779e61aa89eee554d3a47de230bc7ac590d524067c3898bba6f5dc4360b845eda48cbd9cf126a723445f0e1952d7325a75faf556144f9a98af7186b0278685b8e2c08bea87171b4dee585c1828295b5395eb4a17779f0203010001300d06092a864886f70d010105050003818100cb3ab0357d7cd2ae97ed501e51a3a0e2817d418e47fb17906477af61495a7e8d8789141065b082d001f4b15193d0b43fb661cde20a6498372c6abbd3dcb9f0d12659ef07b3c6dbdf8bdf2f65477eed7adcd457d793b1c27badda7c5ade80ce95b7d8827fe78c8a35f3fb4ba648a081be2cfe84231abab3c2b531746df2e0492b000000019a02d5058a04cabe73656c6672656700f2faa56d656b69000004fa8e330003d2d63231343734383336343700000000000002d28e310000</p>

+

+</body>

+</html>
\ No newline at end of file
diff --git a/js/test-encode-decode-ContentObject.html b/js/test-encode-decode-ContentObject.html
index a737d3f..4d55cd7 100644
--- a/js/test-encode-decode-ContentObject.html
+++ b/js/test-encode-decode-ContentObject.html
@@ -4,7 +4,7 @@
 <html xmlns = "http://www.w3.org/1999/xhtml">

 

 <head>

-	<title>NDN Request Example</title>

+	<title>NDN Encode/Decode Content Object</title>

 	

 	<script type="text/javascript" src="java_socket_bridge.js"></script>

 	

@@ -15,9 +15,7 @@
 	<script type="text/javascript" src="ContentName.js"></script>

 	

 	<script type="text/javascript" src="ContentObject.js"></script>

-	

-	<script type="text/javascript" src="DateFormat.js"></script>

-	

+		

 	<script type="text/javascript" src="Exclude.js"></script>

 

 	<script type="text/javascript" src="ExcludeAny.js"></script>

@@ -50,6 +48,8 @@
 	

 	<script type="text/javascript" src="encoding/DataUtils.js"></script>

 	

+	<script type="text/javascript" src="encoding/EncodingUtils.js"></script>

+	

 	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

 	

 	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

@@ -72,11 +72,12 @@
 	<script type="text/javascript">

 	

 		function encode(){

-			var contentname = new ContentName( createNameArray(document.getElementById('contentname').value) );

+			var contentname = new ContentName( document.getElementById('contentname').value );

 			

 			var content = document.getElementById('content').value;

 			

 			var signedInfo = new SignedInfo();

+			

 			signedInfo.setFields();

 			//var signatureBits = generateSignatureBits(contentname,content,signedInfo);

 			

@@ -101,6 +102,7 @@
 			

 			var input = document.getElementById('result').innerHTML;

 

+			input = input.toUpperCase();

 			

 			var co = decodeHexContentObject(input);

 			

@@ -116,59 +118,75 @@
 			else if (co==-2)

 				output+= "CONTENT NAME IS EMPTY"

 			else{

+				

+				

 				if(co.Name!=null && co.Name.Components!=null){

 					output+= "NAME: ";

 					

 					for(var i=0;i<co.Name.Components.length;i++){

-						output+= "/"+ toString(co.Name.Components[i]);

+						output+= "/"+ DataUtils.toString(co.Name.Components[i]);

 					}

 					output+= "<br />";

 					output+= "<br />";

 				}

 	

 				if(co.Content !=null){

-					output += "CONTENT(ASCII): "+ toString(co.Content);

+					output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.Content !=null){

-					output += "CONTENT(hex): "+ toHex(co.Content);

+					output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.Signature !=null && co.Signature.Signature!=null){

 					

-					output += "SIGNATURE(hex): "+ toHex(co.Signature.Signature);

+					output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){

 					

-					output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

+					output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){

+					var d = new Date();

+					d.setTime( co.SignedInfo.Timestamp.msec );

 					

-					output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;

+					var bytes = [217, 185, 12, 225, 217, 185, 12, 225];

 					

+					output += "TimeStamp: "+d;

 					output+= "<br />";

+					output += "TimeStamp(number): "+ co.SignedInfo.Timestamp.msec;

+					

+					

 					output+= "<br />";

 				}

-				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

-					

-					var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));

-					var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

-					var publickeyString = toString(co.SignedInfo.Locator.PublicKey);

-					

-					var signature = toHex(co.Signature.Signature).toLowerCase();

+				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.Certificate!=null){

 					

 					

-					var input = toString(co.rawSignatureData);

+					var tmp = DataUtils.toString(co.SignedInfo.Locator.Certificate);

+					

+					

+					var publickey = rstr2b64(tmp);

+					

+					

+					

+					var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.Certificate).toLowerCase();

+					

+					var publickeyString = DataUtils.toString(co.SignedInfo.Locator.Certificate);

+					

+					var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();

+					

+					

+					var input = DataUtils.toString(co.rawSignatureData);

 					 

 					

 					output += "DER Certificate: "+publickey ;

@@ -179,24 +197,41 @@
 					

 					

 					if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

+					

+					if(LOG>2) console.log("HEX OF ContentName + SignedInfo + Content = ");

+					if(LOG>2) console.log(DataUtils.stringtoBase64(input));

+					

 					if(LOG>2) console.log(" PublicKey = "+publickey );

 					if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

 					if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

 					

-					if(LOG>2) console.log(" Signature "+signature );

-					if(LOG>2) console.log(" Signature NOW IS" );

-					if(LOG>2) console.log(co.Signature.Signature);

-					

-					

+					if(LOG>2) console.log(" Signature is");

+					if(LOG>2) console.log( signature );

+					//if(LOG>2) console.log(" Signature NOW IS" );

+					//if(LOG>2) console.log(co.Signature.Signature);

+

+

 					var x509 = new X509();

-					

+

+

 					x509.readCertPEM(publickey);

 					

-					

 					//x509.readCertPEMWithoutRSAInit(publickey);

 

-					var result = x509.subjectPublicKeyRSA.verifyString(input, signature);

-					console.log('result is '+result);

+					var result = x509.subjectPublicKeyRSA.verifyByteArray(co.rawSignatureData, signature);

+					if(LOG>2) console.log('result is '+result);

+

+					

+					var n = x509.subjectPublicKeyRSA.n;

+					

+					var e =  x509.subjectPublicKeyRSA.e;

+					

+					if(LOG>2) console.log('PUBLIC KEY n after is ');

+					if(LOG>2) console.log(n);

+

+					if(LOG>2) console.log('EXPONENT e after is ');

+					if(LOG>2) console.log(e);

+					

 					/*var rsakey = new RSAKey();

 					

 					var kp = publickeyHex.slice(56,314);

@@ -237,7 +272,114 @@
 					output+= "<br />";

 					

 					

-					if(LOG>4) console.log('str'[1]);

+				    //if(LOG>4) console.log('str'[1]);

+				}

+				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

+					

+

+					var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));

+					var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

+					var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);

+					

+					var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();

+					

+					

+					var input = DataUtils.toString(co.rawSignatureData);

+					 

+					

+					output += "DER Certificate: "+publickey ;

+			

+					output+= "<br />";

+					output+= "<br />";

+					

+					if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

+					if(LOG>2) console.log(" PublicKey = "+publickey );

+					if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

+					if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

+					

+					if(LOG>2) console.log(" Signature "+signature );

+					

+					if(LOG>2) console.log(" Signature NOW IS" );

+					

+					if(LOG>2) console.log(co.Signature.Signature);

+					

+					

+					/*var x509 = new X509();

+					

+					x509.readCertPEM(publickey);

+					

+					

+					//x509.readCertPEMWithoutRSAInit(publickey);

+

+					var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/

+					//console.log('result is '+result);

+					

+					

+					var kp = publickeyHex.slice(56,314);

+					

+					output += "PUBLISHER KEY(hex): "+kp ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					console.log('PUBLIC KEY IN HEX is ');

+					console.log(kp);

+

+					var exp = publickeyHex.slice(318,324);

+					

+					console.log('kp size is '+kp.length );

+					output += "exponent: "+exp ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					console.log('EXPONENT is ');

+					console.log(exp);

+

+					

+					

+					/*var c1 = hex_sha256(input);

+					var c2 = signature;

+					

+					if(LOG>4)console.log('input is ');

+					if(LOG>4)console.log(input);

+					if(LOG>4)console.log('C1 is ');

+					if(LOG>4)console.log(c1);

+					if(LOG>4)console.log('C2 is ');

+					if(LOG>4)console.log(c2);

+					var result = c1 == c2;*/

+					

+					var rsakey = new RSAKey();

+					

+					rsakey.setPublic(kp,exp);

+					

+					var result = rsakey.verifyByteArray(co.rawSignatureData,signature);

+				   // var result = rsakey.verifyString(input, signature);

+					

+				    

+				    

+				    console.log('PUBLIC KEY n after is ');

+					console.log(rsakey.n);

+

+					console.log('EXPONENT e after is ');

+					console.log(rsakey.e);

+					

+					

+					if(result)

+						output += 'SIGNATURE VALID';

+					else

+						output += 'SIGNATURE INVALID';

+

+						

+					

+					

+					//output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					

+					//if(LOG>4) console.log('str'[1]);

 				}

 			}

 			

@@ -264,8 +406,9 @@
 	<button onclick="decode()">Decode</button>

 	

 	

+	<p id="result">048202aa03b20885a8592ebf94205e85de1b143fb423680729910012bce6e2c9b2045e2988b2d7a358bf659d8bd714fbf1859560df6dacef07d07760e29d37a9a71d61ed51d04aa1ba1f6470fb985e3a328e5dcc215bc4c3aa61e3fe8f609709b34912dda892463e611fd86af2e69ff7688008f0dd1ee5680a037be308f4fbb1aef333ad33bf31170000f2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b455900fa02b5c12e4d2e4b00e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabdfd04fcc87f5ade00fa8d00000001a203e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0002bab504fcc88dd36f0002c29d28463f0003d29e3630300003da8d000001e201eaf2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b455900fa02b5c12e4d2e4b00e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabdfd04fcc87f5ade0000000000019a0a9530819f300d06092a864886f70d010101050003818d0030818902818100b945ae17ef820242f542eb1af9eb92ad00a475741db5f8b4cb9d3a1131ad7f7d977e7b7809258f50cee91b56d6f16adb9c7a9492fe004f789bc5d4919b309740f910c26b8603d3f165bb62fef303663df67f244370492c6f1c5e5e9917fe7d4a3f6b0756760a805c467bcb0f143a159e267dc10eb1f4320f1ff2f247c3cbfd25020301000100000000000</p>

+	<!--  p id="result">058203e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004d29632310004da9631370004e2c631302e312e312e310004eaa6393639350003d2d6323134373438333634370000</p-->

 

-		<p id="result"></p>

 

 </body>

 </html>
\ No newline at end of file
diff --git a/js/test-encode-decode-Interest.html b/js/test-encode-decode-Interest.html
index 37b9f23..8fdffe0 100644
--- a/js/test-encode-decode-Interest.html
+++ b/js/test-encode-decode-Interest.html
@@ -4,7 +4,7 @@
 <html xmlns = "http://www.w3.org/1999/xhtml">

 

 <head>

-	<title>NDN Request Example</title>

+	<title>NDN Encocde/Decode Interest</title>

 	

 	<script type="text/javascript" src="java_socket_bridge.js"></script>

 	

@@ -50,6 +50,8 @@
 	

 	<script type="text/javascript" src="encoding/DataUtils.js"></script>

 	

+	<script type="text/javascript" src="encoding/EncodingUtils.js"></script>

+	

 	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

 	

 	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

@@ -74,6 +76,8 @@
 		function encode(){

 			var interest = new Interest( new ContentName(document.getElementById('interest').value ) );

 

+			interest.Scope = 1;

+			

 			var output = encodeToHexInterest(interest);

 			

 			document.getElementById('result').innerHTML = output;

@@ -99,13 +103,65 @@
 			if(interest.Name!=null && interest.Name.Components!=null){

 				output+= "NAME: ";

 				

-				for(var i=0;i<interest.Name.Components.length;i++){

-					output+= "/"+ toString(interest.Name.Components[i]);

-				}

+				

+				output+= interest.Name.getName();

+				

+				/*for(var i=0;i<interest.Name.Components.length;i++){

+					output+= "/"+ DataUtils.toString(interest.Name.Components[i]);

+				}*/

+				

 				output+= "<br />";

 				output+= "<br />";

 			}

 	

+			

+			if(interest.Scope!=null ){

+				output+= "SCOPE: ";

+				

+					output+=  interest.Scope;

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+	

+			if(interest.PublisherID!=null ){

+				output+= "PUBLISHER ID: ";

+				

+					output+=  interest.PublisherID.PublisherID;

+					

+					output+= "PUBLISHER ID TYPE: ";

+					output+=  interest.PublisherID.PublisherType;

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.MaxSuffixComponents!=null ){

+				output+= "MaxSuffixComponents : ";

+				

+				output+=  interest.MaxSuffixComponents;

+

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.MinSuffixComponents!=null ){

+				output+= "MinSuffixComponents : ";

+				

+				output+=  interest.MinSuffixComponents;

+

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			if(interest.MinSuffixComponents!=null ){

+				output+= "MinSuffixComponents : ";

+				

+				output+=  interest.MinSuffixComponents;

+

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

 			document.getElementById('result').innerHTML = output;

 			

 		}

@@ -124,9 +180,11 @@
 	<button onclick="encode()">Encode</button>

 	<button onclick="decode()">Decode</button>

 	

+			<p id="result">01D2F2FAA574657374000000</p>

+	

 	

 

-		<p id="result"></p>

+		<!--  p id="result">01d2f2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b4559000002d28e310000</p-->

 

 </body>

 </html>
\ No newline at end of file
diff --git a/js/test-image-parsing.html b/js/test-image-parsing.html
new file mode 100644
index 0000000..3ce9b84
--- /dev/null
+++ b/js/test-image-parsing.html
@@ -0,0 +1,127 @@
+<?xml version = "1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"DTD/xhtml1-strict.dtd">
+<html xmlns = "http://www.w3.org/1999/xhtml">
+
+<head>
+	<title>NDN Request Example</title>
+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>
+	
+	<script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>
+	
+	<script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.min.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.min.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.min.js"></script>
+	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.min.js"></script>
+
+		
+	<script type="text/javascript">
+		function sign(){
+			
+			var input = document.getElementById('contentname').value;
+			
+			var  _PEM_PRIVATE_KEY_STRING_ = document.getElementById('privateKey').value;
+			
+			var rsa = new RSAKey();
+			
+			rsa.readPrivateKeyFromPEMString(_PEM_PRIVATE_KEY_STRING_);
+			
+			var hSig = rsa.signString(input, "sha256");
+			
+			document.getElementById('result').innerHTML = hSig;
+
+		}
+		function verify(){
+			var input = document.getElementById('contentname').value;
+			
+			var signature = document.getElementById('result').innerHTML;
+			
+			var  _PEM_X509CERT_STRING_ = document.getElementById('certificate').value;
+			
+			var x509 = new X509();
+			
+			x509.readCertPEM(_PEM_X509CERT_STRING_);
+			
+			var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
+			
+			if(result)
+				document.getElementById('result').innerHTML = 'SIGNATURE VALID';
+			else
+				document.getElementById('result').innerHTML = 'SIGNATURE INVALID';
+
+			
+		}
+
+	</script>
+	
+
+</head>
+<body >
+	<form>
+		
+		<input id="privateKey" type="hidden" value="-----BEGIN RSA PRIVATE KEY-----
+			MIICWwIBAAKBgQDRhGF7X4A0ZVlEg594WmODVVUIiiPQs04aLmvfg8SborHss5gQ
+			Xu0aIdUT6nb5rTh5hD2yfpF2WIW6M8z0WxRhwicgXwi80H1aLPf6lEPPLvN29EhQ
+			NjBpkFkAJUbS8uuhJEeKw0cE49g80eBBF4BCqSL6PFQbP9/rByxdxEoAIQIDAQAB
+			AoGAA9/q3Zk6ib2GFRpKDLO/O2KMnAfR+b4XJ6zMGeoZ7Lbpi3MW0Nawk9ckVaX0
+			ZVGqxbSIX5Cvp/yjHHpww+QbUFrw/gCjLiiYjM9E8C3uAF5AKJ0r4GBPl4u8K4bp
+			bXeSxSB60/wPQFiQAJVcA5xhZVzqNuF3EjuKdHsw+dk+dPECQQDubX/lVGFgD/xY
+			uchz56Yc7VHX+58BUkNSewSzwJRbcueqknXRWwj97SXqpnYfKqZq78dnEF10SWsr
+			/NMKi+7XAkEA4PVqDv/OZAbWr4syXZNv/Mpl4r5suzYMMUD9U8B2JIRnrhmGZPzL
+			x23N9J4hEJ+Xh8tSKVc80jOkrvGlSv+BxwJAaTOtjA3YTV+gU7Hdza53sCnSw/8F
+			YLrgc6NOJtYhX9xqdevbyn1lkU0zPr8mPYg/F84m6MXixm2iuSz8HZoyzwJARi2p
+			aYZ5/5B2lwroqnKdZBJMGKFpUDn7Mb5hiSgocxnvMkv6NjT66Xsi3iYakJII9q8C
+			Ma1qZvT/cigmdbAh7wJAQNXyoizuGEltiSaBXx4H29EdXNYWDJ9SS5f070BRbAIl
+			dqRh3rcNvpY6BKJqFapda1DjdcncZECMizT/GMrc1w==
+			-----END RSA PRIVATE KEY-----"></input>
+		
+		
+		<input id="certificate" type="hidden" value="-----BEGIN CERTIFICATE-----
+			MIIBvTCCASYCCQD55fNzc0WF7TANBgkqhkiG9w0BAQUFADAjMQswCQYDVQQGEwJK
+			UDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwHhcNMTAwNTI4MDIwODUxWhcNMjAwNTI1
+			MDIwODUxWjAjMQswCQYDVQQGEwJKUDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwgZ8w
+			DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANGEYXtfgDRlWUSDn3haY4NVVQiKI9Cz
+			Thoua9+DxJuiseyzmBBe7Roh1RPqdvmtOHmEPbJ+kXZYhbozzPRbFGHCJyBfCLzQ
+			fVos9/qUQ88u83b0SFA2MGmQWQAlRtLy66EkR4rDRwTj2DzR4EEXgEKpIvo8VBs/
+			3+sHLF3ESgAhAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAEZ6mXFFq3AzfaqWHmCy1
+			ARjlauYAa8ZmUFnLm0emg9dkVBJ63aEqARhtok6bDQDzSJxiLpCEF6G4b/Nv/M/M
+			LyhP+OoOTmETMegAVQMq71choVJyOFE5BtQa6M/lCHEOya5QUfoRF2HF9EjRF44K
+			3OK+u3ivTSj3zwjtpudY5Xo=
+			-----END CERTIFICATE-----"></input>
+
+		Please Enter a Text to sign:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/PARC/CCNX" /> <br />
+	
+	</form>
+	<button onclick="sign()">Encode</button>
+	<button onclick="verify()">Parse</button>
+	
+	<script type="text/javascript">
+		
+		var String = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==';
+		var link = document.createElement('img');
+		link.setAttribute('src',String);
+		
+		document.body.appendChild(link);
+		
+</script>
+
+	<img src="data:image/png;base64,
+iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
+C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
+AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
+REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
+ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
+vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />
+
+		<p id="result"></p>
+
+</body>
+</html>
diff --git a/js/test-publish-data.html b/js/test-publish-data.html
index a67e844..85eaafa 100644
--- a/js/test-publish-data.html
+++ b/js/test-publish-data.html
@@ -4,7 +4,7 @@
 <html xmlns = "http://www.w3.org/1999/xhtml">

 

 <head>

-	<title>NDN Request Example</title>

+	<title>NDN Publish</title>

 	<script type="text/javascript" src="java_socket_bridge.js"></script>

 	

 	<script type="text/javascript" src="CCNProtocolDTags.js"></script>

@@ -49,6 +49,11 @@
 	

 	<script type="text/javascript" src="encoding/DataUtils.js"></script>

 	

+	<script type="text/javascript" src="encoding/EncodingUtils.js"></script>

+	

+	<script type="text/javascript" src="lwNDN.js"></script>

+	

+	

 	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

 	

 	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

@@ -78,10 +83,7 @@
 			

 			//createRoute('borges.metwi.ucla.edu', 9695);

 			

-			createRoute('localhost', 9695);

-			

-			registerPrefix(ContentName, Content);

-			

+

 			

 			

 			///////////////////////////////////////

@@ -93,7 +95,9 @@
 			//content object

 			//var co = queryPrefix( ContentName );

 			

-			

+			var connector = new lwNDN('127.0.0.1', 9695);

+		    

+			var co = connector.put( ContentName, Content );

 			

 			///////////////////////////////////////

 			

@@ -156,13 +160,14 @@
 

 		Please Enter a Content Name:<br />

 		

-		<input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" /> 

+		<input id="contentname" type="text" name="CONTENTNAME" value="/meki" /> 

 		

 		Please Enter the Content:<br />

 		

-		<textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS"  >SUCCESS!</textarea> 

+		<textarea id="content" cols="40" rows="5" name="CONTENT" value="cherkaoui"  >cherkaoui</textarea> 

 		

 		<br />

+		

 	</form>

 	<button onclick="run()">Publish</button>

 	<div >

diff --git a/js/test-request-data.html b/js/test-request-data.html
index 704d133..11a69b0 100644
--- a/js/test-request-data.html
+++ b/js/test-request-data.html
@@ -4,7 +4,7 @@
 <html xmlns = "http://www.w3.org/1999/xhtml">

 

 <head>

-	<title>NDN Request Example</title>

+	<title>NDN Request </title>

 	<script type="text/javascript" src="java_socket_bridge.js"></script>

 	

 	<script type="text/javascript" src="CCNProtocolDTags.js"></script>

@@ -50,6 +50,10 @@
 	

 	<script type="text/javascript" src="encoding/DataUtils.js"></script>

 	

+	<script type="text/javascript" src="encoding/EncodingUtils.js"></script>

+	

+		<script type="text/javascript" src="lwNDN.js"></script>

+	

 	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

 	

 	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

@@ -71,54 +75,47 @@
 

 	<script type="text/javascript">

 		function run(){

-			//console.log(unescape('%04%82%02%AA%03%B2%08%85H%8EY%0C%94p%F1-%C5%E2%23lW%19%8B%0D%25%81%8D%DEBeNX%BA%0D%D0%10W%7D%BA%9F%C6%8C%2AU%BC%B8%BA%5E%F3%D1l%CDmJ%EE%C4%9D%21%0F%0Djhm%1Ah%86P%D91x%26%AC%B8%8Co%C1%CF%29.l6Mc%B4%DC%C8%D4%86%97%8F%D2%1A%7C%A2%ED%93%89%F3%E9%9D%3C%E0%D4%90%28%D4%11%A2%5D%08%EB%A4%AF%96j%15%A5s%C8%D2Jr%96q%0F%87%7F%D5%D7%B3%D3T%96%F3%16L%00%00%F2%00%01%A2%03%E2%02%85%20Ht%04Z%9F%AC%98%EB%B7%DF%AD%C4%BB%D1%AB%15%A6%E4%06SI%C6%C8%3A%84%60%84N%AB1%85%00%02%BA%B5%04%FA%C3%F9%D7%97%00%01%E2%01%DA%0A%950%81%9F0%0D%06%09%2A%86H%86%F7%0D%01%01%01%05%00%03%81%8D%000%81%89%02%81%81%00%BD%95eU%9C%17%95%C0I%A5%EFM%C9%D1%BC%8B%98%1Bf%09~%A2S%F5%D0%F5%0F%1A%1D%F9%08%ACNi%A7%97%DA%DD%2C%05%90%94Jn%84%9E%1F%BBsq%C5%3D%FD%DB%E7%80%26V%E1%D5%F4I%B8S%0D%9C%7D%A8%D6%AB%EB%D9%0E%06%12M%92%7F%2FlW%21%F1%D0%E4%9E%7Fj%11g%CA%F9%60%D9o%F5%AF%AA-%25g3wr%A9D%C8%E6%CE%B8Y%B2Z%23%1D%9E%CA%875t%FF%98%22%5C%85%3F8%EF%02%03%01%00%01%00%00%00%01%9A%06%8D%05%82%04%CA%BEnewface%00%03%E2%02%85%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F%00%04%D2%8E0%00%04%DA%9617%00%04%E2%CE127.0.0.1%00%04%EA%A69695%00%03%D2%D62147483647%00%00%00%00'));

-			

-			//var a = escape('%04%82%02%AA%03%B2%08%85L%90%D5X%2C%B06wHi%C5%E2%1C%03%D2M%5DB%BF%A5%8C%C8%E8g%99%EB%A7%84%25l%8EB%92%3E%AA%D8%F6%85t%FF%BB%CE%3D%B1%F4%F8%27%A7%1D.%B0%EEU%A6%06%AB%CD%1F3%C6W%93%A9%10X%28-7%7CW%D4%E4%8A3%CF%2B%E4%95%D6%B2%1D%3B%7C%E8%7C%88%7D%7B%F5%80%BC%F7%28%3A%FC%F5w%5B%8C%24%0E%0A%24%DBk%9B%8D%B5%28d%D0A%1E%BEq%0F%0Cc%DB%15%B6%26%1B%E7%E3%E3XL%00%00%F2%00%01%A2%03%E2%02%85%20Ht%04Z%9F%AC%98%EB%B7%DF%AD%C4%BB%D1%AB%15%A6%E4%06SI%C6%C8%3A%84%60%84N%AB1%85%00%02%BA%B5%04%FA%C4%C7%D3I%00%01%E2%01%DA%0A%950%81%9F0%0D%06%09%2A%86H%86%F7%0D%01%01%01%05%00%03%81%8D%000%81%89%02%81%81%00%BD%95eU%9C%17%95%C0I%A5%EFM%C9%D1%BC%8B%98%1Bf%09~%A2S%F5%D0%F5%0F%1A%1D%F9%08%ACNi%A7%97%DA%DD%2C%05%90%94Jn%84%9E%1F%BBsq%C5%3D%FD%DB%E7%80%26V%E1%D5%F4I%B8S%0D%9C%7D%A8%D6%AB%EB%D9%0E%06%12M%92%7F%2FlW%21%F1%D0%E4%9E%7Fj%11g%CA%F9%60%D9o%F5%AF%AA-%25g3wr%A9D%C8%E6%CE%B8Y%B2Z%23%1D%9E%CA%875t%FF%98%22%5C%85%3F8%EF%02%03%01%00%01%00%00%00%01%9A%06%8D%05%82%04%CA%BEnewface%00%03%E2%02%85%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F%00%04%D2%8E0%00%04%DA%9617%00%04%E2%CE127.0.0.1%00%04%EA%A69695%00%03%D2%D62147483647%00%00%00%00');

-			

-			//var n = a.replace("%","");

-			

-			//console.log(n);

 

-			var ContentName = document.getElementById('contentname').value;

+

+			var contentName = document.getElementById('contentname').value;

 		

 			///////////////////////////////////////

-		    createRoute('localhost', 9695);

-			

-			

-			///  /ndn/ucla.edu/apps/hydra/mainvideo

-		    //createRoute('131.179.141.15', 9695);

+			//createRoute('131.179.141.15', 9695);

 		    //createRoute('borges.metwi.ucla.edu', 9695);

+		    ///  /ndn/ucla.edu/apps/hydra/mainvideo

+		    ///////////////////////////////////////

+		

+			var connector = new lwNDN('127.0.0.1', 9695);

 		    

-			//content object

-			var co = queryPrefix( ContentName );

+			var co = connector.get( contentName );

 			

 			///////////////////////////////////////

+			//PRINT OUTPUT

+			///////////////////////////////////////

 			

 			var output ="";

 			

-			if(co==-1)

+			if(co==null)

 				output+= "NO CONTENT FOUND"

-			else if (co==-2)

-				output+= "CONTENT NAME IS EMPTY"

 			else{

 				if(co.Name!=null && co.Name.Components!=null){

 					output+= "NAME: ";

 					

 					for(var i=0;i<co.Name.Components.length;i++){

-						output+= "/"+ toString(co.Name.Components[i]);

+						output+= "/"+ DataUtils.toString(co.Name.Components[i]);

 					}

 					output+= "<br />";

 					output+= "<br />";

 				}

 	

 				if(co.Content !=null){

-					output += "CONTENT(ASCII): "+ toString(co.Content);

+					output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.Content !=null){

-					output += "CONTENT(hex): "+ toHex(co.Content);

+					output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);

 					

 					output+= "<br />";

 					output+= "<br />";

@@ -126,35 +123,40 @@
 				

 				if(co.Signature !=null && co.Signature.Signature!=null){

 					

-					output += "SIGNATURE(hex): "+ toHex(co.Signature.Signature);

+					output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){

 					

-					output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

+					output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){

 					

-					output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;

+					output += "TimeStamp: "+ co.SignedInfo.Timestamp.getJavascriptDate();

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					output += "TimeStamp (MILLISECONDS): "+ co.SignedInfo.Timestamp.msec;

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

 					

-					var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));

-					var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

-					var publickeyString = toString(co.SignedInfo.Locator.PublicKey);

+					var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));

+					var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

+					var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);

 					

-					var signature = toHex(co.Signature.Signature).toLowerCase();

+					var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();

 					

 					

-					var input = toString(co.rawSignatureData);

+					var input = DataUtils.toString(co.rawSignatureData);

 					 

 					

 					output += "DER Certificate: "+publickey ;

@@ -163,14 +165,16 @@
 					output+= "<br />";

 					

 					

-					

+

 					if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

 					if(LOG>2) console.log(" PublicKey = "+publickey );

 					if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

 					if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

 					

 					if(LOG>2) console.log(" Signature "+signature );

+					

 					if(LOG>2) console.log(" Signature NOW IS" );

+					

 					if(LOG>2) console.log(co.Signature.Signature);

 					

 					

@@ -192,8 +196,9 @@
 					output+= "<br />";

 					output+= "<br />";

 					

-					console.log('kp is '+kp);

-					

+					console.log('PUBLIC KEY IN HEX is ');

+					console.log(kp);

+

 					var exp = publickeyHex.slice(318,324);

 					

 					console.log('kp size is '+kp.length );

@@ -202,11 +207,37 @@
 					output+= "<br />";

 					output+= "<br />";

 					

-					console.log('exp is '+exp);

+					console.log('EXPONENT is ');

+					console.log(exp);

+

+					

+					

+					/*var c1 = hex_sha256(input);

+					var c2 = signature;

+					

+					if(LOG>4)console.log('input is ');

+					if(LOG>4)console.log(input);

+					if(LOG>4)console.log('C1 is ');

+					if(LOG>4)console.log(c1);

+					if(LOG>4)console.log('C2 is ');

+					if(LOG>4)console.log(c2);

+					var result = c1 == c2;*/

 					

 					var rsakey = new RSAKey();

+					

 					rsakey.setPublic(kp,exp);

-				    var result = rsakey.verifyString(input, signature);

+					

+					var result = rsakey.verifyByteArray(co.rawSignatureData,signature);

+				   // var result = rsakey.verifyString(input, signature);

+					

+				    

+				    

+				    console.log('PUBLIC KEY n after is ');

+					console.log(rsakey.n);

+

+					console.log('EXPONENT e after is ');

+					console.log(rsakey.e);

+					

 					

 					if(result)

 						output += 'SIGNATURE VALID';

@@ -222,7 +253,7 @@
 					output+= "<br />";

 					

 					

-					if(LOG>4) console.log('str'[1]);

+					//if(LOG>4) console.log('str'[1]);

 				}

 			}

 			

diff --git a/js/test-request-send-hex.html b/js/test-request-send-hex.html
new file mode 100644
index 0000000..922d340
--- /dev/null
+++ b/js/test-request-send-hex.html
@@ -0,0 +1,304 @@
+<?xml version = "1.0" encoding="utf-8" ?>

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

+"DTD/xhtml1-strict.dtd">

+<html xmlns = "http://www.w3.org/1999/xhtml">

+

+<head>

+	<title>NDN Send Hex</title>

+	<script type="text/javascript" src="java_socket_bridge.js"></script>

+	

+	<script type="text/javascript" src="CCNProtocolDTags.js"></script>

+	

+	<script type="text/javascript" src="CCNTime.js"></script>

+	

+	<script type="text/javascript" src="ContentName.js"></script>

+	

+	<script type="text/javascript" src="ContentObject.js"></script>

+	

+	<script type="text/javascript" src="DateFormat.js"></script>

+	

+	<script type="text/javascript" src="Exclude.js"></script>

+

+	<script type="text/javascript" src="ExcludeAny.js"></script>

+

+	<script type="text/javascript" src="ExcludeComponent.js"></script>

+

+	<script type="text/javascript" src="Interest.js"></script>

+	

+	<script type="text/javascript" src="KeyLocator.js"></script>

+	

+	<script type="text/javascript" src="KeyName.js"></script>

+

+	<script type="text/javascript" src="PublisherID.js"></script>

+	

+	<script type="text/javascript" src="Signature.js"></script>

+	

+	<script type="text/javascript" src="SignedInfo.js"></script>

+	

+	<script type="text/javascript" src="PublisherPublicKeyDigest.js"></script>

+	

+	<script type="text/javascript" src="FaceInstance.js"></script>

+	

+	<script type="text/javascript" src="ForwardingEntry.js"></script>

+	

+	

+	<script type="text/javascript" src="encoding/BinaryXMLEncoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLCodec.js"></script>

+	

+	<script type="text/javascript" src="encoding/BinaryXMLDecoder.js"></script>

+	

+	<script type="text/javascript" src="encoding/DataUtils.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>

+	

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script>

+	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script>

+

+	<script type="text/javascript">

+		function run(){

+			//console.log(unescape('%04%82%02%AA%03%B2%08%85H%8EY%0C%94p%F1-%C5%E2%23lW%19%8B%0D%25%81%8D%DEBeNX%BA%0D%D0%10W%7D%BA%9F%C6%8C%2AU%BC%B8%BA%5E%F3%D1l%CDmJ%EE%C4%9D%21%0F%0Djhm%1Ah%86P%D91x%26%AC%B8%8Co%C1%CF%29.l6Mc%B4%DC%C8%D4%86%97%8F%D2%1A%7C%A2%ED%93%89%F3%E9%9D%3C%E0%D4%90%28%D4%11%A2%5D%08%EB%A4%AF%96j%15%A5s%C8%D2Jr%96q%0F%87%7F%D5%D7%B3%D3T%96%F3%16L%00%00%F2%00%01%A2%03%E2%02%85%20Ht%04Z%9F%AC%98%EB%B7%DF%AD%C4%BB%D1%AB%15%A6%E4%06SI%C6%C8%3A%84%60%84N%AB1%85%00%02%BA%B5%04%FA%C3%F9%D7%97%00%01%E2%01%DA%0A%950%81%9F0%0D%06%09%2A%86H%86%F7%0D%01%01%01%05%00%03%81%8D%000%81%89%02%81%81%00%BD%95eU%9C%17%95%C0I%A5%EFM%C9%D1%BC%8B%98%1Bf%09~%A2S%F5%D0%F5%0F%1A%1D%F9%08%ACNi%A7%97%DA%DD%2C%05%90%94Jn%84%9E%1F%BBsq%C5%3D%FD%DB%E7%80%26V%E1%D5%F4I%B8S%0D%9C%7D%A8%D6%AB%EB%D9%0E%06%12M%92%7F%2FlW%21%F1%D0%E4%9E%7Fj%11g%CA%F9%60%D9o%F5%AF%AA-%25g3wr%A9D%C8%E6%CE%B8Y%B2Z%23%1D%9E%CA%875t%FF%98%22%5C%85%3F8%EF%02%03%01%00%01%00%00%00%01%9A%06%8D%05%82%04%CA%BEnewface%00%03%E2%02%85%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F%00%04%D2%8E0%00%04%DA%9617%00%04%E2%CE127.0.0.1%00%04%EA%A69695%00%03%D2%D62147483647%00%00%00%00'));

+			

+			//var a = escape('%04%82%02%AA%03%B2%08%85L%90%D5X%2C%B06wHi%C5%E2%1C%03%D2M%5DB%BF%A5%8C%C8%E8g%99%EB%A7%84%25l%8EB%92%3E%AA%D8%F6%85t%FF%BB%CE%3D%B1%F4%F8%27%A7%1D.%B0%EEU%A6%06%AB%CD%1F3%C6W%93%A9%10X%28-7%7CW%D4%E4%8A3%CF%2B%E4%95%D6%B2%1D%3B%7C%E8%7C%88%7D%7B%F5%80%BC%F7%28%3A%FC%F5w%5B%8C%24%0E%0A%24%DBk%9B%8D%B5%28d%D0A%1E%BEq%0F%0Cc%DB%15%B6%26%1B%E7%E3%E3XL%00%00%F2%00%01%A2%03%E2%02%85%20Ht%04Z%9F%AC%98%EB%B7%DF%AD%C4%BB%D1%AB%15%A6%E4%06SI%C6%C8%3A%84%60%84N%AB1%85%00%02%BA%B5%04%FA%C4%C7%D3I%00%01%E2%01%DA%0A%950%81%9F0%0D%06%09%2A%86H%86%F7%0D%01%01%01%05%00%03%81%8D%000%81%89%02%81%81%00%BD%95eU%9C%17%95%C0I%A5%EFM%C9%D1%BC%8B%98%1Bf%09~%A2S%F5%D0%F5%0F%1A%1D%F9%08%ACNi%A7%97%DA%DD%2C%05%90%94Jn%84%9E%1F%BBsq%C5%3D%FD%DB%E7%80%26V%E1%D5%F4I%B8S%0D%9C%7D%A8%D6%AB%EB%D9%0E%06%12M%92%7F%2FlW%21%F1%D0%E4%9E%7Fj%11g%CA%F9%60%D9o%F5%AF%AA-%25g3wr%A9D%C8%E6%CE%B8Y%B2Z%23%1D%9E%CA%875t%FF%98%22%5C%85%3F8%EF%02%03%01%00%01%00%00%00%01%9A%06%8D%05%82%04%CA%BEnewface%00%03%E2%02%85%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F%00%04%D2%8E0%00%04%DA%9617%00%04%E2%CE127.0.0.1%00%04%EA%A69695%00%03%D2%D62147483647%00%00%00%00');

+			

+			//var n = a.replace("%","");

+			

+			//console.log(n);

+

+			var hex = document.getElementById('contentname').value;

+		

+			///////////////////////////////////////

+		    //createRoute(, 9695);

+			

+			

+			///  /ndn/ucla.edu/apps/hydra/mainvideo

+		    //createRoute('131.179.141.15', 9695);

+		    //createRoute('borges.metwi.ucla.edu', 9695);

+		    

+			//content object

+			//var co = queryPrefix( ContentName );

+			console.log('HEX IS');

+			console.log(hex);

+			

+		    var result = get_java_socket_bridge().connectAndStart('localhost',9695,hex);

+			

+			console.log('BINARY RESPONSE IS ' +result);

+			

+			var output ="";

+			output += "HEX ANSWER IS: "+ result;

+			

+			output+= "<br />";

+			output+= "<br />";

+

+			//result[0] and result[1] should be 0 and 4 if there is a content object found

+			if(result==null || result==undefined || result =="" ){

+				

+				

+				if(LOG>2)console.log('INVALID ANSWER');

+				output += "NO CONTENT FOUND";

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			

+			else if(result[0] != '0'||result[1]!='4') {

+				if(LOG>2)console.log('INVALID ANSWER');

+				output += "INVALID ANSWER";

+				

+				output+= "<br />";

+				output+= "<br />";

+			}

+			else{

+				

+				var numbers = DataUtils.toNumbers(result);

+				

+				console.log('HEX RESPONSE IS \n'+numbers);

+				decoder = new BinaryXMLDecoder(numbers);

+				

+				

+				co = new ContentObject();

+	        

+				co.decode(decoder);

+

+				if(LOG>2) console.log(co);

+			

+				///////////////////////////////////////

+				

+				

+				if(co==-1)

+					output+= "NO CONTENT FOUND"

+				else if (co==-2)

+					output+= "CONTENT NAME IS EMPTY"

+				else{

+					if(co.Name!=null && co.Name.Components!=null){

+						output+= "NAME: ";

+						

+						for(var i=0;i<co.Name.Components.length;i++){

+							output+= "/"+  DataUtils.toString(co.Name.Components[i]);

+						}

+						output+= "<br />";

+						output+= "<br />";

+					}

+		

+					if(co.Content !=null){

+						output += "CONTENT(ASCII): "+  DataUtils.toString(co.Content);

+						

+						output+= "<br />";

+						output+= "<br />";

+					}

+					if(co.Content !=null){

+						output += "CONTENT(hex): "+  DataUtils.toHex(co.Content);

+						

+						output+= "<br />";

+						output+= "<br />";

+					}

+					

+					if(co.Signature !=null && co.Signature.Signature!=null){

+						

+						output += "SIGNATURE(hex): "+  DataUtils.toHex(co.Signature.Signature);

+						

+						output+= "<br />";

+						output+= "<br />";

+					}

+					if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){

+						

+						output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

+						

+						output+= "<br />";

+						output+= "<br />";

+					}

+					if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){

+						

+						output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;

+						

+						output+= "<br />";

+						output+= "<br />";

+					}

+					if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

+						

+						var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));

+						var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

+						var publickeyString = toString(co.SignedInfo.Locator.PublicKey);

+						

+						var signature = toHex(co.Signature.Signature).toLowerCase();

+						

+						

+						var input = toString(co.rawSignatureData);

+						 

+						

+						output += "DER Certificate: "+publickey ;

+						

+						output+= "<br />";

+						output+= "<br />";

+						

+						

+	

+						if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

+						if(LOG>2) console.log(" PublicKey = "+publickey );

+						if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

+						if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

+						

+						if(LOG>2) console.log(" Signature "+signature );

+						

+						if(LOG>2) console.log(" Signature NOW IS" );

+						

+						if(LOG>2) console.log(co.Signature.Signature);

+						

+						

+						/*var x509 = new X509();

+						

+						x509.readCertPEM(publickey);

+						

+						

+						//x509.readCertPEMWithoutRSAInit(publickey);

+	

+						var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/

+						//console.log('result is '+result);

+						

+						

+						var kp = publickeyHex.slice(56,314);

+						

+						output += "PUBLISHER KEY(hex): "+kp ;

+						

+						output+= "<br />";

+						output+= "<br />";

+						

+						console.log('PUBLIC KEY IN HEX is ');

+						console.log(kp);

+	

+						var exp = publickeyHex.slice(318,324);

+						

+						console.log('kp size is '+kp.length );

+						output += "exponent: "+exp ;

+						

+						output+= "<br />";

+						output+= "<br />";

+						

+						console.log('EXPONENT is ');

+						console.log(exp);

+	

+						var rsakey = new RSAKey();

+						

+						rsakey.setPublic(kp,exp);

+						

+					    var result = rsakey.verifyString(input, signature);

+						

+					    console.log('PUBLIC KEY n after is ');

+						console.log(rsakey.n);

+	

+						console.log('EXPONENT e after is ');

+						console.log(rsakey.e);

+						

+						

+						if(result)

+							output += 'SIGNATURE VALID';

+						else

+							output += 'SIGNATURE INVALID';

+	

+							

+						

+						

+						//output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);

+						

+						output+= "<br />";

+						output+= "<br />";

+						

+						

+						//if(LOG>4) console.log('str'[1]);

+					}

+				}

+			}

+			document.getElementById('result').innerHTML = output;

+		}

+	

+		</script>

+	

+</head>

+<body >

+	<form>

+		Please Enter a Content Name:<br /><input id="contentname" type="text" name="CONTENTNAME" value="01D2F2FAA55041524300FA9D616263000000" /> <br />

+	</form>

+	<button onclick="run()">Request Data!</button>

+	<div >

+		<applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">

+		</applet>

+	</div>

+

+		<p id="result"></p>

+

+</body>

+</html>
\ No newline at end of file
diff --git a/js/test-sha256.html b/js/test-sha256.html
index 3d9055c..f30f4de 100644
--- a/js/test-sha256.html
+++ b/js/test-sha256.html
@@ -22,13 +22,19 @@
 	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.min.js"></script>

 	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.min.js"></script>

 

-		

+	<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/sha256.js"></script>

+	

+			

 	<script type="text/javascript">

 		function hash(){

 			

 			var input = document.getElementById('contentname').value;

 			

-			var output = hex_sha256(input);

+			var output = "TEST1 "+hex_sha256(input);

+			

+			output+= "<br />";

+			

+			output += "TEST2 " +CryptoJS.SHA256(input);

 			

 			document.getElementById('result').innerHTML = output;

 

diff --git a/js/test-signature-binary.html b/js/test-signature-binary.html
index b808b98..967d048 100644
--- a/js/test-signature-binary.html
+++ b/js/test-signature-binary.html
@@ -22,7 +22,7 @@
 	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.min.js"></script>

 	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.min.js"></script>

 

-		

+

 	<script type="text/javascript">

 		function sign(){

 			

diff --git a/js/test-signature-string.html b/js/test-signature-string.html
index 99a9fbb..dd57ff6 100644
--- a/js/test-signature-string.html
+++ b/js/test-signature-string.html
@@ -21,14 +21,20 @@
 	<script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.min.js"></script>

 	<script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.min.js"></script>

 	<script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.min.js"></script>

-

+<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

+	

 		

 	<script type="text/javascript">

 		function sign(){

 			

+			

+			var keyManager = new KeyManager();

+			

+			

+			

 			var input = document.getElementById('contentname').value;

 			

-			var  _PEM_PRIVATE_KEY_STRING_ = document.getElementById('privateKey').value;

+			var  _PEM_PRIVATE_KEY_STRING_ = keyManager.privateKey;//document.getElementById('privateKey').value;

 			

 			var rsa = new RSAKey();

 			

@@ -107,5 +113,8 @@
 

 		<p id="result"></p>

 

+		

+	

 </body>

-</html>
\ No newline at end of file
+

+</html>