/** * Convert a byte array to a hex string * * @param bytes byte array to convert to a hex string * @return return a String in hex representing the byte array */ public String toHexString(byte[] bytes) { StringBuffer result = new StringBuffer("0x"); for (int i = 0; i < bytes.length; i++) { Byte aByte = new Byte(bytes[i]); Integer anInt = new Integer(aByte.intValue()); String hexVal = Integer.toHexString(anInt.intValue()); if (hexVal.length() > SIZE) hexVal = hexVal.substring(hexVal.length() - SIZE); result.append( (SIZE > hexVal.length() ? ZEROS.substring(0, SIZE - hexVal.length()) : "") + hexVal); } return (result.toString()); }