Class CryptoHash.GenericHash
java.lang.Object
br.net.dd.netherwingcore.common.cryptography.CryptoHash.GenericHash
- Enclosing class:
CryptoHash
GenericHash class that wraps a MessageDigest instance and provides a convenient API for hashing data.
-
Constructor Summary
ConstructorsConstructorDescriptionGenericHash(CryptoHash.DigestCreator creator, int digestLength) Constructs a GenericHash with the specified DigestCreator and digest length. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this GenericHash, including its current state.Finalizes the digest computation and resets the internal state for reuse.byte[]Returns a copy of the computed digest.static byte[]getDigestOf(CryptoHash.DigestCreator creator, int digestLength, byte[] data) Static utility method to compute the digest of the given data using the specified DigestCreator and digest length.static byte[]getDigestOf(CryptoHash.DigestCreator creator, int digestLength, Object... parts) Static utility method to compute the digest of the given string using the specified DigestCreator and digest length.update(byte[] data) Updates the hash with the specified byte array.update(byte[] data, int offset, int len) Updates the hash with a portion of the specified byte array.Updates the hash with the specified string, using UTF-8 encoding.
-
Constructor Details
-
GenericHash
Constructs a GenericHash with the specified DigestCreator and digest length.- Parameters:
creator- the DigestCreator to create MessageDigest instancesdigestLength- the expected length of the digest output
-
-
Method Details
-
copy
Creates a copy of this GenericHash, including its current state.- Returns:
- a new GenericHash instance with the same state
-
update
Updates the hash with the specified byte array.- Parameters:
data- the data to update the hash with- Returns:
- this GenericHash instance for chaining
-
update
Updates the hash with a portion of the specified byte array.- Parameters:
data- the data to update the hash withoffset- the starting offset in the datalen- the number of bytes to use from the data- Returns:
- this GenericHash instance for chaining
-
update
Updates the hash with the specified string, using UTF-8 encoding.- Parameters:
s- the string to update the hash with- Returns:
- this GenericHash instance for chaining
-
finalizeDigest
Finalizes the digest computation and resets the internal state for reuse.- Returns:
- this GenericHash instance for chaining
-
getDigest
public byte[] getDigest()Returns a copy of the computed digest.- Returns:
- a byte array containing the digest
-
getDigestOf
Static utility method to compute the digest of the given data using the specified DigestCreator and digest length.- Parameters:
creator- the DigestCreator to create MessageDigest instancesdigestLength- the expected length of the digest outputdata- the data to compute the digest of- Returns:
- a byte array containing the computed digest
-
getDigestOf
public static byte[] getDigestOf(CryptoHash.DigestCreator creator, int digestLength, Object... parts) Static utility method to compute the digest of the given string using the specified DigestCreator and digest length.- Parameters:
creator- the DigestCreator to create MessageDigest instancesdigestLength- the expected length of the digest outputparts- the strings to compute the digest of- Returns:
- a byte array containing the computed digest
-