Blake2b Class

Computes the BLAKE2b hash function (RFC 7693), with a digest of 1 to 64 bytes.

public sealed class Blake2b

Remarks

Use the static Blake2b.HashData methods to hash data in one call, or an instance to append the data in several calls. Keyed hashing (BLAKE2b used as a MAC) is not supported.

Instances are not thread-safe.

Constructors

NameDescription
Blake2b(int)Initializes a new instance of the Blake2b class.

Blake2b(int)

Blake2b.cs

Initializes a new instance of the Blake2b class.

public Blake2b(int hashSize = 64)

Parameters

hashSize int
The size of the digest, in bytes: 1 to Blake2b.MaxHashSize.

Exceptions

ArgumentOutOfRangeException
hashSize is not in the range 1 to Blake2b.MaxHashSize.

Properties

NameDescription
HashSizeGets the size of the digest, in bytes.

HashSize

Blake2b.cs

Gets the size of the digest, in bytes.

public int HashSize { get; }

Property value

int

Methods

NameDescription
AppendData(ReadOnlySpan<byte>)Appends data to the message.
GetHashAndReset()Computes the digest of the appended data, and restarts the computation of a new digest of the same size.
GetHashAndReset(Span<byte>)Computes the digest of the appended data into a buffer, and restarts the computation of a new digest of the same size.
HashData(ReadOnlySpan<byte>, int)Computes the BLAKE2b digest of data.
HashData(ReadOnlySpan<byte>, Span<byte>)Computes the BLAKE2b digest of data into a buffer.

AppendData(ReadOnlySpan<byte>)

Blake2b.cs

Appends data to the message.

public void AppendData(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>
The data to append.

GetHashAndReset overloads

GetHashAndReset()

Blake2b.cs

Computes the digest of the appended data, and restarts the computation of a new digest of the same size.

public byte[] GetHashAndReset()
Returns

byte[] The digest, of Blake2b.HashSize bytes.

GetHashAndReset(Span<byte>)

Blake2b.cs

Computes the digest of the appended data into a buffer, and restarts the computation of a new digest of the same size.

public void GetHashAndReset(Span<byte> destination)
Parameters
destination Span<byte>
The buffer that receives the digest: its length must be Blake2b.HashSize.
Exceptions
ArgumentException
The length of destination is not Blake2b.HashSize.

HashData overloads

HashData(ReadOnlySpan<byte>, int)

Blake2b.cs

Computes the BLAKE2b digest of data.

public static byte[] HashData(ReadOnlySpan<byte> source, int hashSize = 64)
Parameters
source ReadOnlySpan<byte>
The data to hash.
hashSize int
The size of the digest, in bytes: 1 to Blake2b.MaxHashSize.
Returns

byte[] The digest, of hashSize bytes.

Exceptions
ArgumentOutOfRangeException
hashSize is not in the range 1 to Blake2b.MaxHashSize.

HashData(ReadOnlySpan<byte>, Span<byte>)

Blake2b.cs

Computes the BLAKE2b digest of data into a buffer.

public static void HashData(ReadOnlySpan<byte> source, Span<byte> destination)
Parameters
source ReadOnlySpan<byte>
The data to hash.
destination Span<byte>
The buffer that receives the digest: its length, 1 to Blake2b.MaxHashSize bytes, is the size of the digest.
Exceptions
ArgumentOutOfRangeException
The length of destination is not in the range 1 to Blake2b.MaxHashSize.

Constants

NameDescription
MaxHashSizeThe maximum size of a digest, in bytes (RFC 7693 section 2.1, nn).

MaxHashSize

The maximum size of a digest, in bytes (RFC 7693 section 2.1, nn).

public const int MaxHashSize = 64