Advertisement
OwniiEU

Untitled

May 2nd, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package eu.ownii.quiz.statics;
  2.  
  3. import java.io.UnsupportedEncodingException;
  4. import java.security.MessageDigest;
  5. import java.security.NoSuchAlgorithmException;
  6.  
  7. public class MD5 {
  8.  
  9.     public static String hash(String string) throws Exception {
  10.        
  11.         String digest = null;
  12.         try {
  13.             MessageDigest md = MessageDigest.getInstance("MD5");
  14.             byte[] hash = md.digest(string.getBytes("UTF-8"));
  15.            
  16.             //converting byte array to Hexadecimal String
  17.            StringBuilder sb = new StringBuilder(2*hash.length);
  18.            for(byte b : hash){
  19.                sb.append(String.format("%02x", b&0xff));
  20.            }
  21.          
  22.            digest = sb.toString();
  23.          
  24.         } catch (UnsupportedEncodingException ex) {
  25.         } catch (NoSuchAlgorithmException ex) {
  26.         }
  27.         return digest;
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement