Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Arrays;
- public class Main {
- /**
- * @param args
- * @throws Exception
- * @throws UnsupportedEncodingException
- */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- String pass = "blabla";
- String salt = "9B3AF463E1270DC5511D86293D23C0D1"; //Result suppose to be 535791F2391DCE9AD6FEBB9C49DC53FD
- byte[] decoded = new byte[salt.length() / 2];
- byte[] b_pass = pass.getBytes();
- for (int i = 0; i < decoded.length; i++) {
- decoded[i] = (byte) Integer.parseInt(salt.substring(i * 2, i * 2 + 2), 16);
- }
- byte[] b_combined = new byte[decoded.length + b_pass.length];
- System.arraycopy(decoded, 0, b_combined, 0, decoded.length);
- System.arraycopy(b_pass, 0, b_combined, decoded.length, b_pass.length);
- // get the MD5 digest library, not sure why this isn't just part of the jdk
- MessageDigest md5 = null;
- try {
- md5 = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- // error handling here...
- }
- // add the bytes to our digest
- md5.update(b_combined);
- // get the digest bytes
- byte[] b_combined_hasehd = md5.digest();
- System.out.println(getHexString(b_combined_hasehd).toUpperCase()); //Result in 535791F2391DCE9AD6FEBB9C49DC53FD
- }
- public static String getHexString(byte[] b) throws Exception {
- String result = "";
- for (int i=0; i < b.length; i++) {
- result +=
- Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement