public static String calculateMd5 ( String input , String encoding ) throws NoSuchAlgorithmException , UnsupportedEncodingException { MessageDigest md = MessageDigest . getInstance ( "MD5" ) ; md . update ( input . getBytes ( encoding ) ) ; byte digest [ ] = md . digest ( ) ; final StringBuilder hexString = new StringBuilder ( ) ; for ( byte element : digest ) { int z = 0xFF & element ; if ( z < 16 ) hexString . append ( "0" ) ; hexString . append ( Integer . toHexString ( z ) ) ; } return hexString . toString ( ) ; }
Calculates MD5 hash for string .