SecureHash
Keywords: net.corda.core.crypto.SecureHash class
Date: 2023-09-18

net.corda.core.crypto

## Class SecureHash

- net.corda.core.utilities.ByteSequence
- - net.corda.core.utilities.OpaqueBytes
  - - net.corda.core.crypto.SecureHash

- Direct Known Subclasses:
    SecureHash.HASH, SecureHash.SHA256

      public class SecureHash
      extends OpaqueBytes

  Container for a cryptographically secure hash value. Provides utilities for generating a cryptographic hash using different algorithms (currently only SHA-256 supported).

- - ### Field Detail

    - #### SHA2_256

          @NotNull
          public static java.lang.String SHA2_256

      See Also:
        Constant Field Values

    - #### SHA2_384

          @NotNull
          public static java.lang.String SHA2_384

      See Also:
        Constant Field Values

    - #### SHA2_512

          @NotNull
          public static java.lang.String SHA2_512

      See Also:
        Constant Field Values

    - #### DELIMITER

          public static char DELIMITER

      See Also:
        Constant Field Values

    - #### zeroHash

          @JvmField
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 zeroHash

      A SHA-256 hash value consisting of 32 0x00 bytes. This field provides more intuitive access from Java.

    - #### allOnesHash

          @JvmField
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 allOnesHash

      A SHA-256 hash value consisting of 32 0xFF bytes. This field provides more intuitive access from Java.

    - #### Companion

          public static net.corda.core.crypto.SecureHash.Companion Companion

  - ### Method Detail

    - #### toHexString

          @NotNull
          public java.lang.String toHexString()

    - #### toString

          @NotNull
          public java.lang.String toString()

    - #### prefixChars

          @NotNull
          public java.lang.String prefixChars(int prefixLen)

      Returns the first `prefixLen` hexadecimal digits of the `class SecureHash` value.

      Parameters:
        `prefixLen` - The number of characters in the prefix.
      See Also:
        `prefixLen`, `class SecureHash`

    - #### hashConcat

          @NotNull
          public net.corda.core.crypto.SecureHash.SHA256 hashConcat(@NotNull
                                                                             SecureHash other)

      Append a second hash value to this hash value, and then compute the SHA-256 hash of the result.

      Parameters:
        `other` - The hash to append to this one.

    - #### concatenate

          @NotNull
          public SecureHash concatenate(@NotNull
                                                 SecureHash other)

      Append a second hash value to this hash value, and then compute the hash of the result.

      Parameters:
        `other` - The hash to append to this one.

    - #### concatenateAs

          @NotNull
          public SecureHash concatenateAs(@NotNull
                                                   java.lang.String concatAlgorithm,
                                                   @NotNull
                                                   SecureHash other)

      Append a second hash value to this hash value, and then compute the hash of the result using the specified algorithm.

      Parameters:
        `concatAlgorithm` - The hash algorithm to use for the resulting hash.
        `other` - The hash to append to this one.

    - #### generate

          @NotNull
          protected SecureHash generate(@NotNull
                                                 kotlin.Array[] data)

    - #### reHash

          @NotNull
          public SecureHash reHash()

    - #### create

          @JvmStatic
           @NotNull
          public static SecureHash create(@Nullable
                                                               java.lang.String str)

      Converts a SecureHash hash value represented as a {algorithm:}hexadecimal String into a `class SecureHash`.

      Parameters:
        `str` - An optional algorithm id followed by a delimiter and the sequence of hexadecimal digits that represents a hash value.
      Throws:
        `IllegalArgumentException` - The input string does not contain the expected number of hexadecimal digits, or it contains incorrectly-encoded characters.
      See Also:
        String, `class SecureHash`

    - #### parse

          @JvmStatic
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 parse(@Nullable
                                                                                           java.lang.String str)

      Converts a SHA-256 hash value represented as a hexadecimal String into a `class SecureHash`.

      Parameters:
        `str` - A sequence of 64 hexadecimal digits that represents a SHA-256 hash value.
      Throws:
        `IllegalArgumentException` - The input string does not contain 64 hexadecimal digits, or it contains incorrectly-encoded characters.
      See Also:
        String, `class SecureHash`

    - #### createSHA256

          @JvmStatic
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 createSHA256(@NotNull
                                                                                                  kotlin.Array[] bytes)

      Factory method for SHA256 to be used in preference to the constructor.

    - #### hashAs

          @JvmStatic
           @NotNull
          public static SecureHash hashAs(@NotNull
                                                               java.lang.String algorithm,
                                                               @NotNull
                                                               kotlin.Array[] bytes)

      Computes the hash value of the ByteArray.

      Parameters:
        `algorithm` - Java provider name of the digest algorithm.
        `bytes` - The ByteArray to hash.
      See Also:
        ByteArray

    - #### componentHashAs

          @JvmStatic
           @NotNull
          public static SecureHash componentHashAs(@NotNull
                                                                        java.lang.String algorithm,
                                                                        @NotNull
                                                                        kotlin.Array[] bytes)

      Computes the digest of the ByteArray which is resistant to pre-image attacks. It computes the hash of the hash for SHA2-256 and other algorithms loaded via JCA MessageDigest. For custom algorithms the strategy can be modified via `interface DigestAlgorithm`.

      Parameters:
        `algorithm` - The MessageDigest algorithm to use.
        `bytes` - The ByteArray to hash.
      See Also:
        ByteArray, MessageDigest, `interface DigestAlgorithm`

    - #### nonceHashAs

          @JvmStatic
           @NotNull
          public static SecureHash nonceHashAs(@NotNull
                                                                    java.lang.String algorithm,
                                                                    @NotNull
                                                                    kotlin.Array[] bytes)

      Computes the digest of the ByteArray which is resistant to pre-image attacks. It computes the hash of the hash for SHA2-256 and other algorithms loaded via JCA MessageDigest. For custom algorithms the strategy can be modified via `interface DigestAlgorithm`.

      Parameters:
        `algorithm` - The MessageDigest algorithm to use.
        `bytes` - The ByteArray to hash.
      See Also:
        ByteArray, MessageDigest, `interface DigestAlgorithm`

    - #### sha256

          @JvmStatic
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 sha256(@NotNull
                                                                                            kotlin.Array[] bytes)

      Computes the SHA-256 hash value of the ByteArray.

      Parameters:
        `bytes` - The ByteArray to hash.
      See Also:
        ByteArray

    - #### sha256Twice

          @JvmStatic
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 sha256Twice(@NotNull
                                                                                                 kotlin.Array[] bytes)

      Computes the SHA-256 hash of the ByteArray, and then computes the SHA-256 hash of the hash.

      Parameters:
        `bytes` - The ByteArray to hash.
      See Also:
        ByteArray

    - #### sha256

          @JvmStatic
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 sha256(@NotNull
                                                                                            java.lang.String str)

      Computes the SHA-256 hash of the String's UTF-8 byte contents.

      Parameters:
        `str` - String whose UTF-8 contents will be hashed.
      See Also:
        String

    - #### randomSHA256

          @JvmStatic
           @NotNull
          public static net.corda.core.crypto.SecureHash.SHA256 randomSHA256()

      Generates a random SHA-256 value.

    - #### random

          @JvmStatic
           @NotNull
          public static SecureHash random(@NotNull
                                                               java.lang.String algorithm)

      Generates a random hash value.

    - #### zeroHashFor

          @JvmStatic
           @NotNull
          public static SecureHash zeroHashFor(@NotNull
                                                                    java.lang.String algorithm)

    - #### allOnesHashFor

          @JvmStatic
           @NotNull
          public static SecureHash allOnesHashFor(@NotNull
                                                                       java.lang.String algorithm)