title: Java MessageDigest MD5 Not Returning Expected Outcome
body: <p>I got extremely bored so I'm making an experimental Brute Forcer. I'm having some issues with MD5 however. I'm getting two very different outputs,</p>
  
  <pre><code>1aabac6d068eef6a7bad3fdf50a05cc8
  -7d881f6ef28afe6a4bb78689e91f6e53
  </code></pre>
  
  <p>The first one is valid and is <code>dd</code>, the second one is invalid, even if I remove the leading hyphen.</p>
  
  <p>I was looking at <a href="https://stackoverflow.com/a/13652007/2179057">this answer</a> and I adjusted what I had to that which solved my primary issue however I'm still getting invalid MD5s.</p>
  
  <p>My code:</p>
  
  <pre><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;
      }
  }
  </code></pre>
  
  <p>In the above, <code>name()</code> just gets <code>"MD5"</code> and <code>getCompare()</code> gets a hash to compare it against.</p>
  
  <p>My question is, how can I fix my code to make sure all the MD5s are valid?</p>