I have implemented AES key schedule in Java but there is one thing I am confused about. In wikipedia (http://en.wikipedia.org/wiki/Rijndael_key_schedule#Key_schedule_description) it says:
The first n bytes of the expanded key are simply the encryption key.
Where does this "encryption key" come from? Is it generated randomly and if so what constraints you should generate it with etc?
At the moment I have a method that just generates a random array of 16 bytes:
public int[][] initvec() {
int[][] key = new int[4][Nk];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < Nk; j++) {
key[i][j] = mrnd.nextInt(255) % (0xff + 1);
int keyval = key[i][j];
// System.out.printf("%x,",keyval);
}
// System.out.println("");
}
return key;
}
I would also like to print this key out however as java only has signed bytes if I use a number larger than 127 (currently 255) I will get negative numbers which can't be represented in a string properly using something like this where outputbyte is byte[] and has the integers converted into bytes and stored inside it:
String output = new String(outputbyte, StandardCharsets.UTF_8);
Is using 127 instead acceptable?