class ByteArrayUtil {

  public static byte[] fromHex(String hex) {
    hex = HEX_IGNORED_CHARS.matcher(hex).replaceAll("").toUpperCase();

    if (hex.length() % 2 != 0) {
      throw new IllegalArgumentException("Odd numbered hex array");
    }

    byte[] byteArray = new byte[hex.length() / 2];
    for (int i = 0; i < hex.length(); i += 2) {
      byteArray[i / 2] =
          (byte)
              ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
    }

    return byteArray;
  }

  private  ByteArrayUtil();

}