TamalinJava wrote:A byte has a fixed size, you cannot change it.
For some reason the size of my byte arrays change, and it is causing problems using an AES Cipher.
The length of the byte array is 16 when I first encrypt text, but when I try and decrypt it, it tells me the length is 29. Then I have an IllegalBlockSizeException.This is your problem. It translates values >= 128 to be two characters.
I used the UTF-8 encoding on Ubuntu 8.04
Can someone explain how to overcome this problem?Don't try to write binary data as if it were text. (Write it as binary data)
I hope this helps...
byte ciphertextBytes = cipher.doFinal(plaintext); //creates a 16 byte array. String ciphertext = new String(ciphertextBytes); //Creates a new string containing the ciphertext bytes. byte newCiphertextBytes = ciphertext.getBytes(); //Creates a 28 byte array!!! (Even though the String 'ciphertext was created with 16)