[英]How to Authenticate MD5
I creating MD5 this way: 我用这种方式创建MD5:
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 输入123456我们得到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. 例如,如果我输入e1adc3949ba59abbe56e057f2f883e和“123456”,那么我得到结果:true / false。
Any idea how to achieve this? 知道怎么做到这一点?
thanks, ray. 谢谢,雷。
String pass = "123456";
String secret = "e1adc3949ba59abbe56e057f2f883e";
if encrypeUsername(pass).equals(secret) System.out.printl("ok!")
Remember that md5 is one-way. 请记住,md5是单向的。 It is hard* to get the password from the secret back again.
很难*再次从密码中获取密码。
(*)Not so hard nowerdays for weak passwords. (*)弱密码不是那么难。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.