public class Hash extends SimpleDataStructure
Hash provides cryptographic hash functionality throughout I2P:
Key Uses:
Performance Features:
Security Properties:
Common Operations:
Constants:
HASH_LENGTH - Standard 32-byte hash sizeFAKE_HASH - All-zero hash for testing/placeholder useThread Safety:
Best Practices:
| Modifier and Type | Field and Description |
|---|---|
static Hash | FAKE_HASHPlaceholder all-zero hash for testing. |
static int | HASH_LENGTHLength of SHA-256 hash in bytes. |
_data| Constructor and Description |
|---|
Hash()Create an empty hash (data is null) |
Hash(byte[] data)IllegalArgumentException if data is not 32 bytes (null is ok). |
| Modifier and Type | Method and Description |
|---|---|
static void | clearCache()Clear the hash cache. |
static Hash | create(byte[] data)Pull from cache or return new
WARNING - If the SDS is found in the cache, the passed-in
byte array will be returned to the SimpleByteCache for reuse. |
static Hash | create(byte[] data,
int off)Pull from cache or return new |
static Hash | create(InputStream in)Pull from cache or return new |
int | hashCode()a Hash is a hash, so just use the first 4 bytes for speed |
int | length()Hash length in bytes. |
void | readBytes(InputStream in)Reads the hash from an input stream. |
void | setData(byte[] data)IllegalArgumentException if data is not 32 bytes (null is ok). |
String | toBase32()For convenience. |
String | toBase64()Returns the hash as a Base64 string. |
calculateHash, equals, fromBase64, fromByteArray, getData, read, toByteArray, toString, writeBytespublic static final Hash FAKE_HASH
public static final int HASH_LENGTH
public Hash()
public Hash(byte[] data)
IllegalArgumentException - if data is not 32 bytes (null is ok)public static void clearCache()
public static Hash create(byte[] data)
IllegalArgumentException - if data is not the correct number of bytespublic static Hash create(byte[] data, int off)
ArrayIndexOutOfBoundsException - if not enough bytespublic static Hash create(InputStream in) throws IOException
IOExceptionpublic int hashCode()
hashCode in class SimpleDataStructurepublic int length()
length in class SimpleDataStructurepublic void readBytes(InputStream in) throws DataFormatException, IOException
readBytes in interface DataStructurereadBytes in class SimpleDataStructurein - the stream to readDataFormatException - if the data is improperly formattedIOException - if there was a problem reading the streampublic void setData(byte[] data)
setData in class SimpleDataStructuredata - of correct length, or nullIllegalArgumentException - if data is not 32 bytes (null is ok)public String toBase32()
public String toBase64()
toBase64 in interface DataStructuretoBase64 in class SimpleDataStructure