FileHashes { static String toHex(byte[] bytes) { BigInteger bi = new BigInteger(1, bytes); String hexFormat = "%0" + (bytes.length << 1) + "x"; return String.format(hexFormat, bi); }    }
@Test public void test_toHex() { assertThat(FileHashes.toHex("aloa_bi_bop_a_loula".getBytes())).isEqualTo("616c6f615f62695f626f705f615f6c6f756c61"); for (int index = 0; index < 100; index++) { String random = randomString(); assertThat(FileHashes.toHex(random.getBytes())).as(random).isEqualTo( Hex.encodeHexString(random.getBytes()).toLowerCase()); } }