In the above code I am not getting the same original byte array after converting into String. If I use charsetBane "UTF-16BE", I am getting the original bytes. But in my program I am always using UTF-16LE in all the places. Is there any error or known bug with java unicode encoding using UTF-16LE. Please help me if anyone faced similar kind of issue and I really appreciate it.
Originally posted by Murthy Vaddi: I converted the byte array to a String using new String(byte byteArray, String charsetName)constructor. When I try to decrypt the encrypted String I tried to get the byte again using String.getBytes(charsetName), I am not getting the same byte array.
Correct. A byte array of binary data generated by the AES encryption algorithm is not the same thing as a byte array of UTF-16LE encoded characters. Some of the bytes will be trimmed to fit the UTF-16LE codepage and you end up with garbage.