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

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

hashConcat

fun hashConcat(other: SecureHash): SHA256

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): String

Returns the first prefixLen hexadecimal digits of the SecureHash value.

toString

open fun toString(): String

Convert the hash value to an uppercase hexadecimal String.

Companion Object Properties

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

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.

parse

fun parse(str: String?): SHA256

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

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): SHA256

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.

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

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.

sha256

fun OpaqueBytes.sha256(): SHA256

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

Inheritors

SHA256

class SHA256 : SecureHash

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