Here you can find the source of toHex(byte[] bytes)
private static String toHex(byte[] bytes)
//package com.java2s; // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of import java.math.BigInteger; public class Main { private static String toHex(byte[] bytes) { BigInteger bi = new BigInteger(1, bytes); return String.format("%0" + (bytes.length << 1) + "X", bi); }/*from ww w. j ava2s . c o m*/ }