APIHash

Hash

A sequence of 32 bytes, representing the SHA-256 hash. Hashes are used to refer to objects, trees, and actors.

Instance creation

Hash hash = Hash.from(hexString);
var hash = cn.hashFromHex(hexString);
my $hash = CN::Hash->fromHex($hexString);

Creates an instance representing a 64-digit hex string. This function returns nullundef if the string does not contain a valid hex sequence, or if the length does not match.

Hash hash = Hash.from(bytes);
var hash = cn.hashFromBytes(bytes);
my $hash = CN::Hash->from($bytes);

Creates an instance using the passed 32 bytes. This function returns nullundef if the length of bytes is not exactly 32.

Calculating hashes

		Hash hash = Hash.calculateFor(bytes);
		Hash hash = Hash.calculateFor(bytes.slice(offset, length));
	
		var hash = cn.hashForBytes(bytes);
		var hash = cn.hashForBytes(cn.slice(bytes, offset, length));
	
		my $hash = CN::Hash->calculateFor($bytes);
		my $hash = CN::Hash->calculateFor(substr($bytes, $offset, $length));
	

Calculates the SHA-256 hash of bytes (or a slice of it), and returns the corresponding hash instance.

Accessing the hash bytes

Bytes bytes = hash.bytes;
var bytes = hash.bytes
my $bytes = $hash->bytes;

Returns the 32 bytes of the hash.

See also

Calculating object hashes