Class | Description |
---|---|
Digest |
Message digest.
|
RHash |
Incremental hasher.
|
Enum | Description |
---|---|
HashType |
Type of hashing algorithm.
|
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 HashType
s 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.