title: SHA hash function gives a negative output
body: <p>I'm trying to implement DSA signature algorithm and I'm stuck on a problem. I'm using the <code>java.security</code> <code>MessageDigest</code> class, here's the code:</p>
  
  <pre><code>MessageDigest md;
  md = MessageDigest.getInstance("SHA-1");
  md.update(text.getBytes());
  return new BigInteger(md.digest());
  </code></pre>
  
  <p>Text is a random String object. Problem is that this code gives me negative values of hash, which is not accepted by the algorithm. Am I doing something wrong? Thanks in advance.</p>
  
  <p>P.S. By the way, I've also tried to implement DSA without using BigIntegers, is this possible? I've not found the L and N values lesser than 1024 and 160, so I have no idea what values should I take and what hash-function should I use. Will be very thankful to hear the answers on these questions.</p>