corda / net.corda.core.crypto / SecureHash

SecureHash

sealed class SecureHash : OpaqueBytes

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

Types

HASH

class HASH : SecureHash

SHA256

class SHA256 : SecureHash

SHA-256 is part of the SHA-2 hash function family. Generated hash is fixed size, 256-bits (32-bytes).

Inherited Properties

bytes

val bytes: ByteArray

The bytes are always cloned so that this object becomes immutable. This has been done to prevent tampering with entities such as net.corda.core.crypto.SecureHash and net.corda.core.contracts.PrivacySalt, as well as preserve the integrity of our hash constants net.corda.core.crypto.SecureHash.zeroHash and net.corda.core.crypto.SecureHash.allOnesHash.

Functions

concatenate

fun concatenate(other: SecureHash): SecureHash

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

concatenateAs

fun concatenateAs(concatAlgorithm: String, other: SecureHash): SecureHash

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

generate

open fun generate(data: ByteArray): SecureHash

hashConcat

fun hashConcat(other: SecureHash): <ERROR CLASS>

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

prefixChars

fun prefixChars(prefixLen: Int = 6): <ERROR CLASS>

Returns the first prefixLen hexadecimal digits of the SecureHash value.

reHash

fun reHash(): SecureHash

toHexString

fun toHexString(): String

toString

open fun toString(): String

Companion Object Properties

DELIMITER

const val DELIMITER: Char

SHA2_256

const val SHA2_256: String

SHA2_384

const val SHA2_384: String

SHA2_512

const val SHA2_512: String

allOnesHash

val allOnesHash: SHA256

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

zeroHash

val zeroHash: SHA256

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

Companion Object Functions

allOnesHashFor

fun allOnesHashFor(algorithm: String): SecureHash

componentHashAs

fun componentHashAs(algorithm: String, bytes: ByteArray): SecureHash

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 DigestAlgorithm.

create

fun create(str: String?): SecureHash

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

digestLengthFor

fun digestLengthFor(algorithm: String): Int

getAllOnesHash

fun getAllOnesHash(): SHA256

A SHA-256 hash value consisting of 32 0xFF bytes. This function is provided for API stability.

getZeroHash

fun getZeroHash(): SHA256

A SHA-256 hash value consisting of 32 0x00 bytes. This function is provided for API stability.

hashAs

fun hashAs(algorithm: String, bytes: ByteArray): SecureHash

Computes the hash value of the ByteArray.

nonceHashAs

fun nonceHashAs(algorithm: String, bytes: ByteArray): SecureHash

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 DigestAlgorithm.

parse

fun parse(str: String?): SHA256

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

random

fun random(algorithm: String): SecureHash

Generates a random hash value.

randomSHA256

fun randomSHA256(): SHA256

Generates a random SHA-256 value.

sha256

fun sha256(bytes: ByteArray): SHA256

Computes the SHA-256 hash value of the ByteArray.

fun sha256(str: String): <ERROR CLASS>

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

sha256Twice

fun sha256Twice(bytes: ByteArray): SHA256

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

zeroHashFor

fun zeroHashFor(algorithm: String): SecureHash

Extension Properties

algorithm

val SecureHash.algorithm: String

Hash algorithm.

isZero

val OpaqueBytes.isZero: Boolean

Extension Functions

contextLogger

fun Any.contextLogger(): <ERROR CLASS>

When called from a companion object, returns the logger for the enclosing class.

deserialize

fun <T : Any> ByteSequence.deserialize(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): T

Convenience extension method for deserializing a ByteSequence, utilising the defaults.

deserializeWithCompatibleContext

fun <T : Any> ByteSequence.deserializeWithCompatibleContext(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): ObjectWithCompatibleContext<T>

Additionally returns SerializationContext which was used for encoding. It might be helpful to know SerializationContext to use the same encoding in the reply.

hashAs

fun OpaqueBytes.hashAs(algorithm: String): SecureHash

Compute the algorithm hash for the contents of the OpaqueBytes.

sha256

fun OpaqueBytes.sha256(): SHA256

Compute the SHA-256 hash for the contents of the OpaqueBytes.

Inheritors

HASH

class HASH : SecureHash

SHA256

class SHA256 : SecureHash

SHA-256 is part of the SHA-2 hash function family. Generated hash is fixed size, 256-bits (32-bytes).