private static String getHash ( String str , String algorithm ) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest . getInstance ( algorithm ) ; md . update ( str . getBytes ( ) ) ; byte byteData [ ] = md . digest ( ) ; StringBuilder hexString = new StringBuilder ( ) ; for ( int i = 0 ; i < byteData . length ; i ++ ) { String hex = Integer . toHexString ( 0xff & byteData [ i ] ) ; if ( hex . length ( ) == 1 ) { hexString . append ( ' ' ) ; } hexString . append ( hex ) ; } return hexString . toString ( ) ; }
Return the hezadecimal representation of the string digest given the specified algorithm .