public static String toHex(byte[] bytes){
  StringBuffer buf=new StringBuffer();
  for (int i=0; i < bytes.length; i++) {
    byte b=bytes[i];
    buf.append(toHexDigit((b >> 4) & 0x0F));
    buf.append(toHexDigit(b & 0x0F));
  }
  return buf.toString();
}

public static String toHex ( byte [ ] bytes ) { StringBuffer buf = new StringBuffer ( ) ; for ( int i = 0 ; i < bytes . length ; i ++ ) { byte b = bytes [ i ] ; buf . append ( toHexDigit ( ( b > > 4 ) & 0x0F ) ) ; buf . append ( toHexDigit ( b & 0x0F ) ) ; } return buf . toString ( ) ; }
converts a byte array to a hexadecimal string .
