code: public static byte[] fromHexString(String hexStr) {
      if (!hexStr.matches("^[0-9A-Fa-f]*$"))
        throw new IllegalArgumentException("Invalid hexadecimal string");
      if (hexStr.isEmpty()) return new byte[0];
  
      int complementary = hexStr.length() % 2;
      if (complementary != 0) hexStr += "0";
      return rjust(new BigInteger(hexStr, 16).toByteArray(), hexStr.length() / 2);
    }
docs: Converts a hexadecimal string into byte array.
  
  @param hexStr
  a hexadecimal string
  @return byte array
  @throws IllegalArgumentException
  if hexadecimal string is invalid