The MD5 algorithm in Java.

Class
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class PasswordMD5 {
private String password;

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public void novoPassowd(String pass) throws NoSuchAlgorithmException{
this.setPassword(this.toPassword(pass));
}

public boolean validaPassword(String pass) throws NoSuchAlgorithmException{
String password2 = this.toPassword(pass);
if (this.getPassword().equals(password2)) {
System.out.println(“Pass1: ” + this.getPassword());
System.out.println(“Pass2: ” + password2);
return true;
}else{
System.out.println(“Pass1: ” + this.getPassword());
System.out.println(“Pass2: ” + password2);
return false;
}
}

private String bytesToHex(byte[] b) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < b.length; ++i) {
sb.append((Integer.toHexString((b[i] & 0xFF) | 0x100)).substring(1, 3));
}
return sb.toString();
}

private String toPassword(String data) throws NoSuchAlgorithmException {
byte[] mybytes = data.getBytes();
MessageDigest md5 = MessageDigest.getInstance(“MD5”);
byte[] md5digest = md5.digest(mybytes);
return bytesToHex(md5digest);
}
}

Using the class

public class Main {
public static void main(String[] args) {
try {
PasswordMD5 passmd5 = new PasswordMD5();
passmd5.novoPassowd(“hdi”);
System.out.println(passmd5.validaPassword(“hdi”));
} catch (Exception e) {
e.printStackTrace();
}

}
}

see u…