There are other questions posted here on this topic, most of which involve ByteBuffer and asIntBuffer. However, I have not seen any explaination on how to keep the value from truncating when converting to an IntBuffer.
Example:
byte[] plainTextBytes = "Hello World".getBytes();
// Truncates the limit from 11 to 2
IntBuffer intBuffer = ByteBuffer.wrap( plainTextBytes ).asIntBuffer();
// Results in java.lang.UnsupportedOperationException
int[] plainTextInt = intBuffer.array();
I have an RC4 encryption algorithm which takes a plaintext argument of type int[]. Hence, I need to convert the plaintext into int[]. The problem with ByteBuffer and the use of asIntBuffer is the plaintext is being truncated because the limit is independent (goes from 11 to 2, in my example).
Either I'm doing something wrong or ByteBuffer is not the way to go here.
Any help would be appreciated. Thank you.