[英]Java MessageDigest MD5 Not Returning Expected Outcome
I got extremely bored so I'm making an experimental Brute Forcer. 我非常无聊,所以我正在做一个实验性的Brute Forcer。 I'm having some issues with MD5 however.
我在使用MD5时遇到了一些问题。 I'm getting two very different outputs,
我得到两个非常不同的输出,
1aabac6d068eef6a7bad3fdf50a05cc8
-7d881f6ef28afe6a4bb78689e91f6e53
The first one is valid and is dd
, the second one is invalid, even if I remove the leading hyphen. 即使删除前导连字符,第一个也是有效的,并且是
dd
,第二个无效。
I was looking at this answer and I adjusted what I had to that which solved my primary issue however I'm still getting invalid MD5s. 我一直在寻找这个答案,并调整了解决我的主要问题的解决方案,但是我仍然收到无效的MD5。
My code: 我的代码:
public boolean testValidity(String s) {
try {
MessageDigest md = MessageDigest.getInstance(name());
byte[] hashDigest = md.digest(s.getBytes("UTF-8"));
String hash = String.format("%032x", new BigInteger(md.digest(s.getBytes("UTF-8"))));
System.out.println(hash);
return getCompare().equalsIgnoreCase(hash);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException | NullPointerException e) {
e.printStackTrace();
return false;
}
}
In the above, name()
just gets "MD5"
and getCompare()
gets a hash to compare it against. 在上面的代码中,
name()
仅获得"MD5"
而getCompare()
得到一个哈希值以与之进行比较。
My question is, how can I fix my code to make sure all the MD5s are valid? 我的问题是,如何修复我的代码以确保所有MD5均有效?
Your BigInteger constructor uses twos complement. 您的BigInteger构造函数使用二进制补码。 Use the sign/magnitude variant instead with first parameter 1. http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#BigInteger(int,%20byte[])
使用符号/幅度变体代替第一个参数1。http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#BigInteger(int,%20byte [])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.