Package org.sf.rhash

Java bindings for librhash.

See: Description

Package org.sf.rhash Description

Java bindings for librhash. Librhash is a library for computing and verifying hash sums. List of all supported hash functions can be found in HashType class description.

In its simplest usage to calculate a hash for message or file you just need to use one of RHash.computeHash() methods:

     RHash.computeHash("Hello, world!");
     RHash.computeHash(new byte[] { 0, 1, 2, 3});
     RHash.computeHash(new File("SomeFile.txt"));
These methods return value of type Digest which is a message digest. To convert Digest in human readable format you might use one of methods hex(), base32(), base64() or raw().

Next, RHash allows you to do incremental hashing, processing data given in portions like it was one big byte sequence. To do this you first need to create RHash instance with a set of needed hash algorithms and then to fill it using update():

     RHash hasher = new RHash(HashType.MD5);
     hasher.update("Foo").update(new File("Bar.zip")).finish();
     Digest result = hasher.getDigest();
Method finish() should be called before obtaining digest to end all calculations and generate result.

You can setup RHash to calculate several digests at once, passing corresponding HashTypes in constructor. Specifically, you can calculate all of them creating RHash like

     new Rhash(EnumSet.allOf(HashType.class));
In this case to obtain digest for particular hash type use getDigest(HashType) method.