title: How can I create an SHA512 digest string in Java using bouncy castle?
body: <p>This unit test is failing:</p>
  
  <pre><code>    public void testDigest() throws NoSuchAlgorithmException {
      String hashExpected = "150a14ed5bea6cc731cf86c41566ac427a8db48ef1b9fd626664b3bfbb99071fa4c922f33dde38719b8c8354e2b7ab9d77e0e67fc12843920a712e73d558e197";
      MessageDigest md = new MessageDigest();
      String hashActual = new String(md.digest("hi"));
      Assert.assertEquals(hashExpected, hashActual);
  }
  </code></pre>
  
  <p>Below is my implementation of my MessageDigest class:</p>
  
  <p><pre><code>
  import java.io.IOException;
  import java.io.InputStream;
  import java.security.NoSuchAlgorithmException;
  import java.security.Security;</p>
  
  <p>import org.bouncycastle.crypto.Digest;
  import org.bouncycastle.crypto.digests.SHA512Digest;
  import org.bouncycastle.crypto.io.DigestInputStream;
  import org.bouncycastle.jce.provider.BouncyCastleProvider;</p>
  
  <p>public class MessageDigest {
      private Digest messageDigest;</p>
  
  <pre><code>public MessageDigest() throws NoSuchAlgorithmException {
      Security.addProvider(new BouncyCastleProvider());
      messageDigest = new SHA512Digest();
  }
  
  public byte[] digest(String message) {
      byte[] retValue = new byte[messageDigest.getDigestSize()];
      messageDigest.update(message.getBytes(), 0, message.length());
      messageDigest.doFinal(retValue, 0);
      return retValue;
  }
  </code></pre>
  
  <p>}
  </pre></code></p>
  
  <p>The test fails with the following reason:
  <pre><code>
  junit.framework.ComparisonFailure: expected:&lt;150a14ed5bea6cc731cf86c41566ac427a8db48ef1b9fd626664b3bfbb99071fa4c922f33dde38719b8c8354e2b7ab9d77e0e67fc12843920a712e73d558e197> but was:&lt;
  í[êlÇ1Ï†Äf¬Bz�´Žñ¹ýbfd³¿»™¤É"ó=Þ8q›ŒƒTâ·«�wàæÁ(C’
  q.sÕXá
  </pre></code></p>
  
  <p>I have a feeling I'm not using the right encoding scheme when I convert my byte[] digest into a string.  Any help would be appreciated.</p>