Here you can find the source of toHex(byte[] bytes)
public static String toHex(byte[] bytes)
//package com.java2s; // distribute, sublicense, and/or sell copies of the Software, and to permit import java.nio.charset.Charset; import javax.xml.bind.DatatypeConverter; public class Main { public static String toHex(String s, Charset cs) { return toHex(s.getBytes(cs)); }/*from w ww . j ava 2 s . c o m*/ public static String toHex(String s) { return toHex(s.getBytes(Charset.forName("UTF-8"))); } public static String toHex(byte[] bytes) { return DatatypeConverter.printHexBinary(bytes); } }