code: static byte[] fromHexString(String str) {
      if (str.length() % 2 != 0) {
        throw new InvalidOperationException("Hex-string has odd length!");
      }
      byte[] data = new byte[str.length() / 2];
      int spos = 0;
      for (int dpos = 0; dpos < data.length; dpos++) {
        int d1 = Character.digit(str.charAt(spos++), 16);
        int d2 = Character.digit(str.charAt(spos++), 16);
        if (d1 < 0 || d2 < 0) {
          throw new InvalidOperationException("Mal-formed hex-string!");
        }
        data[dpos] = (byte) ((d1 << 4) | d2);
      }
      return data;
    }
docs: Convert a "hexa"-string to a byte array.
  @param str Input string.
  @return Corresponding array of bytes.