/** * Generate a byte array that is a hex representation of a given byte array. * * @param buffer to convert to a hex representation. * @return new byte array that is hex representation (in Big Endian) of the passed array. */ public static byte[] toHexByteArray(final byte[] buffer) { return toHexByteArray(buffer, 0, buffer.length); }
/** * Generate a string that is the hex representation of a given byte array. * * @param buffer to convert to a hex representation. * @return new String holding the hex representation (in Big Endian) of the passed array. */ public static String toHex(final byte[] buffer) { return new String(toHexByteArray(buffer), UTF_8); }
/** * Generate a string that is the hex representation of a given byte array. * * @param buffer to convert to a hex representation. * @param offset the offset into the buffer. * @param length the number of bytes to convert. * @return new String holding the hex representation (in Big Endian) of the passed array. */ public static String toHex(final byte[] buffer, final int offset, final int length) { return new String(toHexByteArray(buffer, offset, length), UTF_8); }
@Test public void shouldConvertToHexCorrectly() { final byte[] buffer = { 0x01, 0x23, 0x45, 0x69, 0x78, (byte)0xBC, (byte)0xDA, (byte)0xEF, 0x5F }; final byte[] converted = toHexByteArray(buffer); final String hexStr = toHex(buffer); assertThat(converted[0], is((byte)'0')); assertThat(converted[1], is((byte)'1')); assertThat(converted[2], is((byte)'2')); assertThat(converted[3], is((byte)'3')); assertThat(hexStr, is("0123456978bcdaef5f")); }
/** * Generate a byte array that is a hex representation of a given byte array. * * @param buffer to convert to a hex representation * @return new byte array that is hex representation (in Big Endian) of the passed array */ public static byte[] toHexByteArray(final byte[] buffer) { return toHexByteArray(buffer, 0, buffer.length); }
/** * Generate a byte array that is a hex representation of a given byte array. * * @param buffer to convert to a hex representation. * @return new byte array that is hex representation (in Big Endian) of the passed array. */ public static byte[] toHexByteArray(final byte[] buffer) { return toHexByteArray(buffer, 0, buffer.length); }
/** * Generate a string that is the hex representation of a given byte array. * * @param buffer to convert to a hex representation * @param offset the offset into the buffer * @param length the number of bytes to convert * @return new String holding the hex representation (in Big Endian) of the passed array */ public static String toHex(final byte[] buffer, int offset, int length) { return new String(toHexByteArray(buffer, offset, length), UTF8_CHARSET); }
/** * Generate a string that is the hex representation of a given byte array. * * @param buffer to convert to a hex representation * @return new String holding the hex representation (in Big Endian) of the passed array */ public static String toHex(final byte[] buffer) { return new String(toHexByteArray(buffer), UTF8_CHARSET); }
/** * Generate a string that is the hex representation of a given byte array. * * @param buffer to convert to a hex representation. * @param offset the offset into the buffer. * @param length the number of bytes to convert. * @return new String holding the hex representation (in Big Endian) of the passed array. */ public static String toHex(final byte[] buffer, final int offset, final int length) { return new String(toHexByteArray(buffer, offset, length), UTF_8); }
/** * Generate a string that is the hex representation of a given byte array. * * @param buffer to convert to a hex representation. * @return new String holding the hex representation (in Big Endian) of the passed array. */ public static String toHex(final byte[] buffer) { return new String(toHexByteArray(buffer), UTF_8); }
public static String digestAsHex(final MessageDigest messageDigest) { final byte[] digest = messageDigest.digest(); final byte[] hexByteArray = BitUtil.toHexByteArray(digest); return fromBytes(hexByteArray); }
public static String digestAsHex(final MessageDigest messageDigest) { final byte[] digest = messageDigest.digest(); final byte[] hexByteArray = BitUtil.toHexByteArray(digest); return fromBytes(hexByteArray); }