Advertisement
Guest User

Untitled

a guest
Oct 28th, 2011
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 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 Exception
  12.      * @throws UnsupportedEncodingException
  13.      */
  14.     public static void main(String[] args) throws Exception {
  15.         // TODO Auto-generated method stub
  16.         String pass = "blabla";
  17.         String salt = "9B3AF463E1270DC5511D86293D23C0D1"; //Result suppose to be 535791F2391DCE9AD6FEBB9C49DC53FD
  18.        
  19.         byte[] decoded = new byte[salt.length() / 2];
  20.         byte[] b_pass = pass.getBytes();
  21.         for (int i = 0; i < decoded.length; i++) {
  22.             decoded[i] = (byte) Integer.parseInt(salt.substring(i * 2, i * 2 + 2), 16);
  23.         }
  24.        
  25.         byte[] b_combined = new byte[decoded.length + b_pass.length];
  26.         System.arraycopy(decoded, 0, b_combined, 0, decoded.length);
  27.         System.arraycopy(b_pass, 0, b_combined, decoded.length, b_pass.length);
  28.        
  29.         // get the MD5 digest library, not sure why this isn't just part of the jdk
  30.         MessageDigest md5 = null;
  31.         try {
  32.             md5 = MessageDigest.getInstance("MD5");
  33.         } catch (NoSuchAlgorithmException e) {
  34.             // error handling here...
  35.         }
  36.         // add the bytes to our digest
  37.         md5.update(b_combined);
  38.         // get the digest bytes
  39.         byte[] b_combined_hasehd = md5.digest();
  40.        
  41.         System.out.println(getHexString(b_combined_hasehd).toUpperCase()); //Result in 535791F2391DCE9AD6FEBB9C49DC53FD
  42.     }
  43.    
  44.     public static String getHexString(byte[] b) throws Exception {
  45.           String result = "";
  46.           for (int i=0; i < b.length; i++) {
  47.             result +=
  48.                   Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
  49.           }
  50.           return result;
  51.     }
  52. }
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement