1) I couldn’t find the Java implementation anywhere for the JCE AES encryption, but does anyone know if the byte array it takes as an argument is treated as signed or unsigned? The code I’m using is:
public static byte [] ecbAesEncrypt(byte [] key, byte [] currentVector) {
SecretKeySpec keySpec = null;
Cipher cipher = null;
byte [] encryptedValue = null;
try {
keySpec = new SecretKeySpec(key, "AES");
cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
encryptedValue = cipher.doFinal(currentVector);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
if (DEBUG)
printHex("AES-ECB encrypt: ", encryptedValue);
return encryptedValue;
}
2) Will the bitwise XOR of 2 signed bytes give the same results as the bitwise XOR of 2 unsigned bytes? By this I mean that just the bit representations will be the same. I’m thinking yes, but just want to make sure.
3) Somewhat related the question 1, what bitwise operations would produce different results between signed and unsigned bytes?
AES treats the bytes as purely binary data. Not as numbers which have a sign or don’t have a sign.
There are no unsigned bytes in Java. They are always signed. But the sign only matters when you do integer arythmetics on them.
The bitwise operators are described in the Java tutorial.