Advertisement
Guest User

Untitled

a guest
Oct 28th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.security.MessageDigest;
  3. import java.security.NoSuchAlgorithmException;
  4. import java.util.Arrays;
  5.  
  6.  
  7. public class Main {
  8.  
  9.     /**
  10.      * @param args
  11.      * @throws NoSuchAlgorithmException
  12.      * @throws UnsupportedEncodingException
  13.      */
  14.     public static void main(String[] args) {
  15.         // TODO Auto-generated method stub
  16.         String pass = "blabla";
  17.         String salt = "9B3AF463E1270DC5511D86293D23C0D1"; //Result suppose to be 535791F2391DCE9AD6FEBB9C49DC53FD
  18.        
  19.         // convert your hex string to bytes
  20.         byte[] bytesSalt = new BigInteger(salt, 16).toByteArray();
  21.         byte[] bytePass = pass.getBytes();
  22.         // get the MD5 digest library, not sure why this isn't just part of the jdk
  23.         MessageDigest md5Digest = null;
  24.         try {
  25.             md5Digest = MessageDigest.getInstance("MD5");
  26.         } catch (NoSuchAlgorithmException e) {
  27.             // error handling here...
  28.         }
  29.         // add the bytes to our digest
  30.         md5Digest.update(bytesSalt);
  31.         md5Digest.update(bytePass);
  32.         // get the digest bytes
  33.         byte[] digestBytes = md5Digest.digest();
  34.         System.out.println("Digest is " + Arrays.toString(digestBytes));
  35.     }
  36. }
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement