Byte arrays default to having content with a value of zero. So you can just do:
byte[] myVeryWeakKey = new byte[8];
byte[6] = // whatever
byte[7] = //whatever
Or perhaps you want to randomly assign those last two bytes?
byte[] keybits = new byte[2];
Random r = new Random();
r.nextBytes(keybits);
System.arraycopy(keybits, 0, myVeryWeakKey, 6, 2);
I hope it goes without saying that these keys will be pitifully weak. So weak, you needn't bother with any encryption at all. (Which is why I didn't even bother to suggest SecureRandom
).
If you need to create all possible values, something like the following will work:
List<byte[]> keys = new ArrayList<>();
for (int b = -128; b <= 127; b++) {
for (int c = -128; c <= 127; c++) {
byte[] newValue = new byte[8];
newValue[6] = (byte) b;
newValue[7] = (byte) c;
keys.add(newValue);
}
}