示例#1
0
  /**
   * decode the Hex encoded String data - whitespace will be ignored.
   *
   * @return a byte array representing the decoded data.
   */
  public static byte[] decode(String data) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    try {
      encoder.decode(data, bOut);
    } catch (IOException e) {
      throw new RuntimeException("exception decoding Hex string: " + e);
    }

    return bOut.toByteArray();
  }
示例#2
0
  /**
   * encode the input data producing a Hex encoded byte array.
   *
   * @return a byte array containing the Hex encoded data.
   */
  public static byte[] encode(byte[] data, int off, int length) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    try {
      encoder.encode(data, off, length, bOut);
    } catch (IOException e) {
      throw new RuntimeException("exception encoding Hex string: " + e);
    }

    return bOut.toByteArray();
  }