package backend;

import java.nio.ByteBuffer;
/**
 * 
 * @author Fitria
 * added this function to convert bytes to any types
 * from now long to byte is done
 * if necessary, will add bytes convertion to another types here
 *
 */

public class ByteUtils {
	static public byte[] longToBytes(long x) {
	    ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE);
	    buffer.putLong(x);
	    return buffer.array();
	}

	static public long bytesToLong(byte[] bytes) {
	    ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE);
	    buffer.put(bytes);
	    buffer.flip();//need flip 
	    return buffer.getLong();
	}
	
}

@@ -39,16 +39,66 @@
 Buffer;%0A
+import java.util.Arrays;%0Aimport java.util.Random;%0A
 /**%0A * %0A
@@ -300,23 +300,16 @@
 tils %7B%0A%09
-static 
 public b
@@ -454,15 +454,8 @@
 %7D%0A%0A%09
-static 
 publ
@@ -637,11 +637,334 @@
 ();%0A
-
 %09%7D%0A%09%0A
+%09/**%0A%09 * Generate a random Nonces for Mutual Auth%0A%09 * @param length: the random bytes length%0A%09 * @return random bytes array%0A%09 */%0A%09public byte%5B%5D GenerateRandomBytes(int length)%7B%0A%09%09byte%5B%5D random = new byte%5Blength%5D;%0A%09%09%0A%09%09new Random().nextBytes(random);%0A%09%09//System.out.println(Arrays.toString(random));%0A%09%09return random;%0A%09%7D%0A%09%0A%09%0A
 %7D%0A

add generates random nonces for certain bytes length