Class CryptoHash.GenericHash

java.lang.Object
br.net.dd.netherwingcore.common.cryptography.CryptoHash.GenericHash
Enclosing class:
CryptoHash

public static final class CryptoHash.GenericHash extends Object
GenericHash class that wraps a MessageDigest instance and provides a convenient API for hashing data.
  • Constructor Details

    • GenericHash

      public GenericHash(CryptoHash.DigestCreator creator, int digestLength)
      Constructs a GenericHash with the specified DigestCreator and digest length.
      Parameters:
      creator - the DigestCreator to create MessageDigest instances
      digestLength - the expected length of the digest output
  • Method Details

    • copy

      public CryptoHash.GenericHash copy()
      Creates a copy of this GenericHash, including its current state.
      Returns:
      a new GenericHash instance with the same state
    • update

      public CryptoHash.GenericHash update(byte[] data)
      Updates the hash with the specified byte array.
      Parameters:
      data - the data to update the hash with
      Returns:
      this GenericHash instance for chaining
    • update

      public CryptoHash.GenericHash update(byte[] data, int offset, int len)
      Updates the hash with a portion of the specified byte array.
      Parameters:
      data - the data to update the hash with
      offset - the starting offset in the data
      len - the number of bytes to use from the data
      Returns:
      this GenericHash instance for chaining
    • update

      public CryptoHash.GenericHash update(String s)
      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

      public CryptoHash.GenericHash 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

      public 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.
      Parameters:
      creator - the DigestCreator to create MessageDigest instances
      digestLength - the expected length of the digest output
      data - 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 instances
      digestLength - the expected length of the digest output
      parts - the strings to compute the digest of
      Returns:
      a byte array containing the computed digest