hash - Java MessageDigest MD5 Not Returning Expected Outcome -
i got extremely bored i'm making experimental brute forcer. i'm having issues md5 however. i'm getting 2 different outputs,
1aabac6d068eef6a7bad3fdf50a05cc8 -7d881f6ef28afe6a4bb78689e91f6e53
the first 1 valid , dd
, second 1 invalid, if remove leading hyphen.
i looking @ this answer , adjusted had solved primary issue i'm still getting invalid md5s.
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 above, name()
gets "md5"
, getcompare()
gets hash compare against.
my question is, how can fix code make sure md5s valid?
your biginteger constructor uses twos complement. use sign/magnitude variant instead first parameter 1. http://docs.oracle.com/javase/7/docs/api/java/math/biginteger.html#biginteger(int,%20byte[])
Comments
Post a Comment