static public String hexEncode(byte[] aInput){
  StringBuffer result=new StringBuffer();
  final char[] digits={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  for (int idx=0; idx < aInput.length; ++idx) {
    byte b=aInput[idx];
    result.append(digits[(b & 0xf0) >> 4]);
    result.append(digits[b & 0x0f]);
  }
  return result.toString();
}

static public String hexEncode ( byte [ ] aInput ) { StringBuffer result = new StringBuffer ( ) ; final char [ ] digits = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' } ; for ( int idx = 0 ; idx < aInput . length ; ++ idx ) { byte b = aInput [ idx ] ; result . append ( digits [ ( b & 0xf0 ) > > 4 ] ) ; result . append ( digits [ b & 0x0f ] ) ; } return result . toString ( ) ; }
the byte [ ] returned by messagedigest does not have a nice textual representation , so some form of encoding is usually performed . this implementation follows the example of david flanagan ' s book " java in a nutshell " , and converts a byte array into a string of hex characters . another popular alternative is to use a " base64 " encoding .
