public static String getMD5ForString ( String content ) { StringBuilder md5Buffer = new StringBuilder ( ) ; try { MessageDigest digest = MessageDigest . getInstance ( "MD5" ) ; byte [ ] tempBytes = digest . digest ( content . getBytes ( ) ) ; int digital ; for ( int i = 0 ; i < tempBytes . length ; i ++ ) { digital = tempBytes [ i ] ; if ( digital < 0 ) { digital += 256 ; } if ( digital < 16 ) { md5Buffer . append ( "0" ) ; } md5Buffer . append ( Integer . toHexString ( digital ) ) ; } } catch ( Exception ignored ) { return Integer . toString ( content . hashCode ( ) ) ; } return md5Buffer . toString ( ) ; }
Get the MD5 value of string .