0
I’m creating a program that takes a login and a password and encrypts it using MD5,I know that MD5 is not an algorithm that you can call encryption,but is actually a hash,but it does not matter, what I am trying to do is what has already been mentioned and the variable login with MD5 works normal, but the variable password always returns the same result.
Variables :
String login;
String password;
MessageDigest m;
MessageDigest m1;
Encryption process for MD5 :
try
{
m = MessageDigest.getInstance("MD5");
m1 = MessageDigest.getInstance("MD5");
m.update(login.getBytes(),0,login.length());
m1.update(password.getBytes(),0,password.length());
BigInteger login1 = new BigInteger(1, m.digest());
BigInteger password1 = new BigInteger(1, m.digest());
//Formatando o resultado em uma cadeia de 32 caracteres, completando com 0 caso falte
login = String.format("%1$032X", login1);
password = String.format("%1$032X", password1);
System.out.println("MD5: "+ login);
System.out.println("MD5: " + password);
}
In the output :
login : 011DD1032ECECFB4497613E48049972C
password : D41D8CD98F00B204E9800998ECF8427E
In the output of the password always ends up being the same hash, and in the login always end up leaving a different result(a different hash),I wonder how I can fix it to always exit a different result as well as the variable login.
Good that you solved your problem, but anyway remember that in practice MD5 is not a good method to protect passwords. By the way, why are you hashing the login?
– mgibsonbr