public static String bytesToHex(byte[] bytes,boolean withSpaces){
  StringBuilder sb=new StringBuilder();
  for (  byte hashByte : bytes) {
    int intVal=0xff & hashByte;
    if (intVal < 0x10) {
      sb.append('0');
    }
    sb.append(Integer.toHexString(intVal));
    if (withSpaces) {
      sb.append(' ');
    }
  }
  return sb.toString();
}

public static String bytesToHex ( byte [ ] bytes , boolean withSpaces ) { StringBuilder sb = new StringBuilder ( ) ; for ( byte hashByte : bytes ) { int intVal = 0xff & hashByte ; if ( intVal < 0x10 ) { sb . append ( '0' ) ; } sb . append ( Integer . toHexString ( intVal ) ) ; if ( withSpaces ) { sb . append ( ' ' ) ; } } return sb . toString ( ) ; }
takes the provided byte array and converts it into a hexadecimal string with two characters per byte .
