Reputation: 633
My program asks user to input a string of certificate fingerprint then convert the input to byte array for later use.
What I am asking is how should I convert the inputStringArray
to the convertResult
byte array?
String input = "2F:A3:CF:8F:D6:ED:06:79:B8:FB:DB:0E:3B:A4:52:45:83:8E:7F:C5";
String[] inputStringArray = input.trim().split(":");
//convert inputStringArray to results array here
//...
byte[] convertResult = new byte[]
{(byte)0x2f, (byte)0xa3, (byte)0xcf, (byte)0x8f, (byte)0xd6, (byte)0xed, (byte)0x06, (byte)0x79, (byte)0xb8, (byte)0xfb,
(byte)0xdb, (byte)0x0e, (byte)0x3b, (byte)0xa4, (byte)0x52, (byte)0x45, (byte)0x83, (byte)0x8e, (byte)0x7f, (byte)0xc5};
Thanks!
Upvotes: 0
Views: 683
Reputation: 633
answer to my own question:
public static byte[] str2bytes(String input) {
String [] hex_list = input.split(":");
byte[] output = new byte[hex_list.length];
int i = 0;
for (String hex: hex_list) {
output[i] = (byte) Integer.parseInt(hex, 16);
i ++;
}
return output;
}
Upvotes: 0