/** * 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(); }
/** * 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(); }