java.lang.Comparable<HashId>
public class HashId extends java.lang.Object implements java.lang.Comparable<HashId>
v3 uses 3 orthogonal algorithms and concatenates its results to get slightly longer but much more strong hash.
The algorithms are:
1) SHA-512/256, the strongest to the length extension attack SHA2 family variant
2) SHA3-256, which is a different algorithm from sha2 family and is known to be very string
3) ГОСТ Р 34.11-2012 "Stribog" which is a standard in Russian Federation make it eligible in this country. While this hashing algorithm is suspected to be less strong than is stated, in conjunction with two more completely different hashes it makes the result steel solid and bulletproof.
The overall compund hash, consisting of 3 concatenated hashes, requires an attacker to create collision on both 3 in the same time which is way more complex task than finding collision on each of them, as, generally, collision on one algorithm will not work with another.
The classic usage scenatio is packed data of Approvable
documents.
History.
First, the Syntex1
algorighm was used, giving additional protection against some attacks by combining SHA2
and CRC32 as protection against some future collision attacks.
Later, the SHA2-512 was used as its analyse shown very good results.
Finally, as Universa grows, more strength and more jurisdiction compliance were added with v3, having 3 independent algorithms, 2 of them are recognized and recommended by NYST and one is required in Russian federation. We suppose that these algorithms joined together are a very hard hash for the collision attack.
Created by sergeych on 16/07/2017.
Modifier and Type | Class | Description |
---|---|---|
static class |
HashId.CompositeDigest |
Composite digest uses 3 orthogonal algorithms concatenating three different hashes to gether to get longer but
much more strong hash.
|
Modifier and Type | Field | Description |
---|---|---|
protected byte[] |
digest |
Constructor | Description |
---|---|
HashId(byte[] packedData) |
Modifier and Type | Method | Description |
---|---|---|
int |
compareTo(HashId other) |
|
static HashId |
createRandom() |
Create random new hashId.
|
boolean |
equals(java.lang.Object obj) |
|
byte[] |
getDigest() |
|
int |
hashCode() |
|
void |
initWith(byte[] packedData) |
Setup with binary data.
|
static HashId |
of(byte[] data) |
Return new HashId calculating composite digest hash of the data (see
HashId.CompositeDigest class) |
java.lang.String |
toBase64String() |
|
java.lang.String |
toString() |
convert to "compact" base64u string, e.g.
|
static HashId |
withDigest(byte[] hash) |
Create instance from a saved digest (obtained before with
getDigest() . |
static HashId |
withDigest(java.lang.String encodedString) |
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void initWith(byte[] packedData)
IllegalStateException
will be thrown otherwise.packedData
- data to initialize frompublic byte[] getDigest()
public int compareTo(HashId other)
compareTo
in interface java.lang.Comparable<HashId>
public java.lang.String toString()
Base64u
,
Base64.encodeCompactString(byte[])
. Use Base64u#decodeCompactString to restore the digest.toString
in class java.lang.Object
public static HashId createRandom()
Do.randomBytes(int)
instead.public static HashId withDigest(byte[] hash)
getDigest()
.hash
- digest to construct withpublic java.lang.String toBase64String()
public static HashId of(byte[] data)
HashId.CompositeDigest
class)data
- for hashingpublic static HashId withDigest(java.lang.String encodedString)