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).
@NotNull public static java.lang.String SHA2_256
@NotNull public static java.lang.String SHA2_384
@NotNull public static java.lang.String SHA2_512
public static char DELIMITER
@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.
@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.
public static net.corda.core.crypto.SecureHash.Companion Companion
@NotNull public java.lang.String toHexString()
@NotNull public java.lang.String toString()
@NotNull public java.lang.String prefixChars(int prefixLen)
Returns the first prefixLen
hexadecimal digits of the class SecureHash
value.
prefixLen
- The number of characters in the prefix.prefixLen
,
class SecureHash
@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.
other
- The hash to append to this one.@NotNull public SecureHash concatenate(@NotNull SecureHash other)
Append a second hash value to this hash value, and then compute the hash of the result.
other
- The hash to append to this one.@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.
concatAlgorithm
- The hash algorithm to use for the resulting hash.other
- The hash to append to this one.@NotNull protected SecureHash generate(@NotNull kotlin.Array[] data)
@NotNull public SecureHash reHash()
@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
.
str
- An optional algorithm id followed by a delimiter and the sequence of hexadecimal digits that represents a hash value.IllegalArgumentException
- The input string does not contain the expected number of hexadecimal digits, or it contains incorrectly-encoded characters.class SecureHash
@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
.
str
- A sequence of 64 hexadecimal digits that represents a SHA-256 hash value.IllegalArgumentException
- The input string does not contain 64 hexadecimal digits, or it contains incorrectly-encoded characters.class SecureHash
@JvmStatic @NotNull public static SecureHash hashAs(@NotNull java.lang.String algorithm, @NotNull kotlin.Array[] bytes)
Computes the hash value of the ByteArray.
@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
.
algorithm
- The MessageDigest algorithm to use.bytes
- The ByteArray to hash.interface DigestAlgorithm
@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
.
algorithm
- The MessageDigest algorithm to use.bytes
- The ByteArray to hash.interface DigestAlgorithm
@JvmStatic @NotNull public static net.corda.core.crypto.SecureHash.SHA256 sha256(@NotNull kotlin.Array[] bytes)
Computes the SHA-256 hash value of the ByteArray.
@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.
@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.
@JvmStatic @NotNull public static net.corda.core.crypto.SecureHash.SHA256 randomSHA256()
Generates a random SHA-256 value.
@JvmStatic @NotNull public static SecureHash random(@NotNull java.lang.String algorithm)
Generates a random hash value.
@JvmStatic @NotNull public static SecureHash zeroHashFor(@NotNull java.lang.String algorithm)
@JvmStatic @NotNull public static SecureHash allOnesHashFor(@NotNull java.lang.String algorithm)