Fixed bug when converting hex to bytes

This commit is contained in:
Marcin Kostrzewski 2020-10-29 16:43:06 +01:00
parent 3bc287848e
commit 2b0002d7cf

View File

@ -15,7 +15,13 @@ public class Utils {
return hexString.toString(); return hexString.toString();
} }
static byte[] stringToBytes(String hexString) { static byte[] stringToBytes(String s) {
return new BigInteger(hexString, 16).toByteArray(); int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
} }
} }