static String getMd5Hash ( byte [ ] bytes ) throws NoSuchAlgorithmException { String hash ; try { MessageDigest md = MessageDigest . getInstance ( "MD5" ) ; md . update ( bytes ) ; byte [ ] digest = md . digest ( ) ; char [ ] hexCode = "0123456789ABCDEF" . toCharArray ( ) ; StringBuilder r = new StringBuilder ( digest . length * 2 ) ; for ( byte b : digest ) { r . append ( hexCode [ ( b >> 4 ) & 0xF ] ) ; r . append ( hexCode [ ( b & 0xF ) ] ) ; } hash = r . toString ( ) . toUpperCase ( ) ; } catch ( NoSuchAlgorithmException e ) { throw e ; } return hash ; }
Method reads a byte array and returns an upper case md5 hash for it .