I am generating a Session key, that changes every time i run the program. But when i am converting it into BYTE ARRAY then Byte Array generated is same every time i run the program . IT should be different right? Here is my code
Key key;
SecureRandom rand = new SecureRandom();
KeyGenerator generator = KeyGenerator.getInstance("AES");
generator.init(rand);
generator.init(256);
key = generator.generateKey();
String key1=key.toString();
byte[] genratesessionKey1 = key1.getBytes();
System.out.println("SESSION KEY IS(Byte format) "+genratesessionKey1.toString());
Then i also used one dummy string. and then i generated its Byte[]. Then i changed the value in that string and generated its Byte[] Again. Still it returns the same result.
String test2="yadav";
String key1=key.toString();
byte[] genratesessionKey1 = key1.getBytes();
byte[] g2=test.getBytes("UTF-8");
byte[] g3=test.getBytes();
System.out.println("Session key in String "+key1);
System.out.println("Testing Byte Format "+g2);
System.out.println("Testing Byte Format 2 "+g3);
Why Its happening.Any Suggestions will be appreciated