From 2b0002d7cf837fe6d8e0676e0413ae621a78aa78 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Thu, 29 Oct 2020 16:43:06 +0100 Subject: [PATCH] Fixed bug when converting hex to bytes --- src/main/java/Main/Utils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main/Utils.java b/src/main/java/Main/Utils.java index c06d7f7..29d6912 100644 --- a/src/main/java/Main/Utils.java +++ b/src/main/java/Main/Utils.java @@ -15,7 +15,13 @@ public class Utils { return hexString.toString(); } - static byte[] stringToBytes(String hexString) { - return new BigInteger(hexString, 16).toByteArray(); + static byte[] stringToBytes(String s) { + 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; } }