Commitment { public Commitment(byte[] data) throws NoSuchAlgorithmException { this.salt = Digest.makeRand(); byte[] d = serialize(data); this.value = Digest.digest(d); } Commitment(byte[] data); byte[] getSalt(); byte[] getValue(); boolean verify(byte[] opening);  }
@Test public void testCommitment() throws NoSuchAlgorithmException { byte[] msg = "message".getBytes(); Commitment comm = new Commitment(msg); if(comm.getValue().length != Digest.HASH_SIZE_BYTES) { fail("Computation of commitment failed - wrong length."); } assertNotNull("Computation of commitment failed - null", comm.getValue()); assertTrue("Invalid commitment", comm.verify(msg)); }