MD5 Implementation in Java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tester;
import java.security.*;
import java.math.*;

/**
 *
 * @author agung
 */
public class Tester {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        String s="admin";
        try{
            MessageDigest m=MessageDigest.getInstance("MD5");

            m.update(s.getBytes(),0,s.length());
            String encripted;
            //Wajib Di tampung dulu biar hasil encripsi gak berubah
            encripted = new BigInteger(1,m.digest()).toString(16);

            System.out.println("MD5: "+encripted);
            //Kalau gak di tampung dahulu nanti hasil encripsi nya seperti ini
            System.out.println("MD5: "+new BigInteger(1,m.digest()).toString(16));

            String code = "21232f297a57a5a743894a0e4a801fc3";
            if(encripted.equals(code)){

                System.out.println("Sama" );

            }
            else{
                System.out.println("Beda" + new BigInteger(1,m.digest()).toString(16).equals("21232f297a57a5a743894a0e4a801fc3"));
            }

        }
        catch(Exception exception){
        }
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: