Here you can find the source of toHex(byte[] bytes)
public static String toHex(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { public static String toHex(byte[] bytes) { if (bytes != null && bytes.length > 0) { StringBuilder buff = new StringBuilder(bytes.length << 1); String tmp = null;/* ww w.ja v a2 s .com*/ for (int i = 0; i < bytes.length; i++) { tmp = (Integer.toHexString(bytes[i] & 0xFF)); if (tmp.length() == 1) { buff.append('0'); } buff.append(tmp); } return buff.toString(); } return null; } }