SHA512DigestCalculator implements DigestCalculator { @Override public byte[] getDigest() { final byte[] bytes = bos.toByteArray(); bos.reset(); final Digest sha512 = new SHA512Digest(); sha512.update(bytes, 0, bytes.length); byte[] digest = new byte[sha512.getDigestSize()]; sha512.doFinal(digest, 0); return digest; }  @Override AlgorithmIdentifier getAlgorithmIdentifier(); @Override OutputStream getOutputStream(); @Override byte[] getDigest();  }
@Test public void testGetDigest() throws IOException, NoSuchAlgorithmException, NoSuchProviderException { final SHA512DigestCalculator sha512 = new SHA512DigestCalculator(); final byte[] bytes = getClass().getName().getBytes(); sha512.getOutputStream().write(bytes); final byte[] digest = sha512.getDigest(); final MessageDigest messageDigest = MessageDigest.getInstance("SHA-512", BOUNCY_CASTLE); final byte[] digest2 = messageDigest.digest(bytes); assertThat(Arrays.areEqual(digest, digest2), is(true)); final MessageDigest messageDigest2 = MessageDigest.getInstance("SHA-512"); final byte[] digest3 = messageDigest2.digest(bytes); assertThat(Arrays.areEqual(digest, digest3), is(true)); }