I have a String array that actually consists of Hex characters.
Let’s say the contents are ->
String array[] = {8C,D9,26,1D,69,B7,96,DB};
Now I want these to be interpreted as Hex characters of 1 byte each and not as a String where each entry is 2 bytes.
StringBuilder output = new StringBuilder();
for (int j = 0; j < array.length; j++) {
String temp = "\u00"+ array[j];
output.append(temp);
}
Tried something like that, but it’s not possible because it keeps complaining about “illegal unicode escape”. I tried using “\u00” (i.e. two backslashes before u, but stackoverflow displays only one there) instead of “\u00” to get around that error, but then I don’t see the real Hex values in the array, instead I see a bunch of strings like -> “\U008C” , “\U00D9” and so on..
I want the after conversion values to be 0x8C, 0xD9, 0x26…
Thanks.
EDIT: I have updated the question, just to clarify there were no commas in the array itself. And eventually I need to put all those values together, and use that as a HMAC key that is a hex string and NOT a text string.
Let the JDK do the work for you:
Basically just that one line inside the loop is all you need.
If you wanted your input to be just one big String (which would seem more convenient), just do this instead:
Edited:
If you want byte[] result, do this: