Question
I creating MD5 this way:
public void encrypeUsername(String sessionid)
{
byte[] defaultBytes = sessionid.getBytes();
try
{
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(defaultBytes);
byte messageDigest[] = algorithm.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++)
{
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
}
System.out.println("sessionid " + sessionid + " md5 version is " + hexString.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
}
for input 123456 we get MD5: e1adc3949ba59abbe56e057f2f883e
I want to create another method to authenticate the result.
For example if i give an input of e1adc3949ba59abbe56e057f2f883e and "123456" then I get as result: true/false.
Any idea how to achieve this?
thanks, ray.
Solution
String pass = "123456";
String secret = "e1adc3949ba59abbe56e057f2f883e";
if encrypeUsername(pass).equals(secret) System.out.printl("ok!")
Remember that md5 is one-way. It is hard* to get the password from the secret back again.
(*)Not so hard nowerdays for weak passwords.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow