Advertisement
xlrnxnlx

toMD5

Jul 31st, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. public String toMD5( String s )
  2.     {
  3.         try
  4.         {
  5.             MessageDigest mDigest = java.security.MessageDigest.getInstance( "MD5" );
  6.             mDigest.digest( s.getBytes("UTF-8") );
  7.             byte[] digest = mDigest.digest();
  8.            
  9.             StringBuilder str = new StringBuilder();
  10.             for( byte b : digest ){
  11.                 String t = Integer.toHexString( 0xFF & b);
  12.                 while( t.length() < 2 )
  13.                     t = "0" + t;
  14.                 str.append(t);
  15.             }
  16.             return str.toString();
  17.         } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { }
  18.         return null;
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement