Table of Contents

Class Blake2bDigest

Namespace
Org.BouncyCastle.Crypto.Digests
Assembly
BouncyCastle.Cryptography.dll

Implementation of the cryptographic hash function Blake2b. BLAKE2b is optimized for 64-bit platforms and produces digests of any size between 1 and 64 bytes.

public sealed class Blake2bDigest : IDigest
Inheritance
Blake2bDigest
Implements
Inherited Members

Remarks

Blake2b offers a built-in keying mechanism to be used directly for authentication ("Prefix-MAC") rather than a HMAC construction.

Blake2b offers a built-in support for a salt for randomized hashing and a personal string for defining a unique hash function for each application.

Constructors

Blake2bDigest()

Initializes a new instance of Blake2bDigest.

public Blake2bDigest()

Blake2bDigest(Blake2bDigest)

Constructs a new instance of Blake2bDigest from another Blake2bDigest./>.

public Blake2bDigest(Blake2bDigest digest)

Parameters

digest Blake2bDigest

The original instance of Blake2bDigest that is copied.

Blake2bDigest(byte[])

Initializes a new instance of Blake2bDigest with a key.

Blake2b for authentication ("Prefix-MAC mode"). After calling the DoFinal(byte[], int) method, the key will remain to be used for further computations of this instance. The key can be cleared using the ClearKey() method.

public Blake2bDigest(byte[] key)

Parameters

key byte[]

A key up to 64 bytes or null.

Exceptions

ArgumentException

Blake2bDigest(byte[], int, byte[], byte[])

Initializes a new instance of Blake2bDigest with a key, required digest length (in bytes), salt and personalization.

After calling the DoFinal(byte[], int) method, the key, the salt and the personalization will remain and might be used for further computations with this instance. The key can be overwritten using the ClearKey() method, the salt (pepper) can be overwritten using the ClearSalt() method.

public Blake2bDigest(byte[] key, int digestLength, byte[] salt, byte[] personalization)

Parameters

key byte[]

A key up to 64 bytes or null.

digestLength int

Digest length from 1 to 64 bytes.

salt byte[]

A 16 bytes or nullable salt.

personalization byte[]

A 16 bytes or null personalization.

Exceptions

ArgumentException

Blake2bDigest(int)

Initializes a new instance of Blake2bDigest with a given digest size.

public Blake2bDigest(int digestSize)

Parameters

digestSize int

Digest size in bits.

Exceptions

ArgumentException

Properties

AlgorithmName

The algorithm name.

public string AlgorithmName { get; }

Property Value

string

Methods

BlockUpdate(byte[], int, int)

Update the message digest with a block of bytes.

public void BlockUpdate(byte[] message, int offset, int len)

Parameters

message byte[]
offset int
len int

BlockUpdate(ReadOnlySpan<byte>)

Update the message digest with a span of bytes.

public void BlockUpdate(ReadOnlySpan<byte> input)

Parameters

input ReadOnlySpan<byte>

The span containing the data.

ClearKey()

Clears the key.

public void ClearKey()

ClearSalt()

Clears the salt (pepper).

public void ClearSalt()

DoFinal(byte[], int)

Close the digest, producing the final digest value.

public int DoFinal(byte[] output, int outOffset)

Parameters

output byte[]

The byte array the digest is to be copied into.

outOffset int

The offset into the byte array the digest is to start at.

Returns

int

The number of bytes written.

Remarks

The DoFinal(byte[], int) call leaves the digest reset. Key, salt and personal string remain.

DoFinal(Span<byte>)

Close the digest, producing the final digest value.

public int DoFinal(Span<byte> output)

Parameters

output Span<byte>

The span the digest is to be copied into.

Returns

int

The number of bytes written.

Remarks

The DoFinal(Span<byte>) call leaves the digest reset. Key, salt and personal string remain.

GetByteLength()

Return the size in bytes of the internal buffer the digest applies it's compression function to.

public int GetByteLength()

Returns

int

The byte length of the digests internal buffer.

GetDigestSize()

Return the size, in bytes, of the digest produced by this message digest.

public int GetDigestSize()

Returns

int

The size, in bytes, of the digest produced by this message digest.

Reset()

Reset the digest back to it's initial state. The key, the salt and the personalization will remain for further computations.

public void Reset()

Update(byte)

Update the message digest with a single byte.

public void Update(byte b)

Parameters

b byte