Digest { public static byte[] digest(byte[] input) throws NoSuchAlgorithmException { byte [] digest = null; try{ MessageDigest md = MessageDigest.getInstance(HASH_ID); digest = md.digest(input); } finally { return digest; } }  static byte[] digest(byte[] input); static byte[] makeRand(); static final int HASH_SIZE_BITS; static final int HASH_SIZE_BYTES; static final String HASH_ID; }
@Test public void testDigest() throws NoSuchAlgorithmException { byte[] msg = "message".getBytes(); byte[] hash = Digest.digest(msg); if(hash.length != Digest.HASH_SIZE_BYTES) { fail("Computation of hash failed - wrong length."); } assertNotNull("Computation of hash failed - null", hash); assertFalse("Computation of hash failed - hash is all zeros", Arrays.equals(hash, new byte[Digest.HASH_SIZE_BYTES])); }