Class Blake2s
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Hash
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Computes the BLAKE2s hash for the input data.
public sealed class Blake2s : HashAlgorithm, ICryptoTransform, IDisposable, IResettable
- Inheritance
-
Blake2s
- Implements
- Inherited Members
Remarks
This is a fully managed implementation of BLAKE2s that does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.
BLAKE2s is optimized for 32-bit platforms and produces digests from 1 to 32 bytes. The default output size is 32 bytes (256 bits).
BLAKE2s supports an optional key for keyed hashing (MAC mode) with keys up to 32 bytes.
Constructors
Blake2s()
Initializes a new instance of the Blake2s class with default output size (32 bytes).
public Blake2s()
Blake2s(int)
Initializes a new instance of the Blake2s class with specified output size.
public Blake2s(int outputBytes)
Parameters
outputBytesintThe desired output size in bytes (1-32).
Blake2s(int, ReadOnlySpan<byte>)
Initializes a new instance of the Blake2s class with specified output size and key.
public Blake2s(int outputBytes, ReadOnlySpan<byte> key)
Parameters
outputBytesintThe desired output size in bytes (1-32).
keyReadOnlySpan<byte>The optional key for keyed hashing (MAC mode). Must be 0-MaxKeySizeBytes bytes.
Fields
BlockSizeBytes
The block size in bytes.
public const int BlockSizeBytes = 64
Field Value
MaxHashSizeBits
The maximum hash size in bits.
public const int MaxHashSizeBits = 256
Field Value
MaxHashSizeBytes
The maximum hash size in bytes.
public const int MaxHashSizeBytes = 32
Field Value
MaxKeySizeBytes
The maximum key size in bytes.
public const int MaxKeySizeBytes = 32
Field Value
Properties
AlgorithmName
Gets the name of the hash algorithm.
public override string AlgorithmName { get; }
Property Value
BlockSize
Gets the block size in bytes used by the hash algorithm.
public override int BlockSize { get; }
Property Value
IsKeyed
Gets a value indicating whether this instance is configured for keyed hashing (MAC mode).
public bool IsKeyed { get; }
Property Value
Methods
Create()
Creates a new instance of the Blake2s class with default output size.
public static Blake2s Create()
Returns
- Blake2s
A new BLAKE2s instance.
Create(int)
Creates a new instance of the Blake2s class with specified output size.
public static Blake2s Create(int outputBytes)
Parameters
outputBytesintThe desired output size in bytes (1-32).
Returns
- Blake2s
A new BLAKE2s instance.
CreateKeyed(int, ReadOnlySpan<byte>)
Creates a new keyed instance of the Blake2s class.
public static Blake2s CreateKeyed(int outputBytes, ReadOnlySpan<byte> key)
Parameters
outputBytesintThe desired output size in bytes (1-32).
keyReadOnlySpan<byte>The key for keyed hashing (MAC mode). Must be 0-MaxKeySizeBytes bytes.
Returns
- Blake2s
A new BLAKE2s instance configured for keyed hashing.
CreateKeyed(ReadOnlySpan<byte>)
Creates a new keyed instance of the Blake2s class with default output size.
public static Blake2s CreateKeyed(ReadOnlySpan<byte> key)
Parameters
keyReadOnlySpan<byte>The key for keyed hashing (MAC mode). Must be 0-MaxKeySizeBytes bytes.
Returns
- Blake2s
A new BLAKE2s instance configured for keyed hashing.
Dispose(bool)
Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.
protected override void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
HashCore(ReadOnlySpan<byte>)
When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.
protected override void HashCore(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The input to compute the hash code for.
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.
HashData(in ReadOnlySequence<byte>)
Computes the BLAKE2s hash of source using the default output size (32 bytes)
and returns it as a new byte array.
public static byte[] HashData(in ReadOnlySequence<byte> source)
Parameters
sourceReadOnlySequence<byte>The (possibly multi-segment) input sequence to hash.
Returns
- byte[]
A new byte array containing the BLAKE2s hash.
HashData(ReadOnlySpan<byte>)
Computes the BLAKE2s hash of source using the default output size (32 bytes)
and returns it as a new byte array.
public static byte[] HashData(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The input data to hash.
Returns
- byte[]
A new byte array containing the BLAKE2s hash.
Initialize()
Initializes an implementation of the HashAlgorithm class.
public override void Initialize()
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.
TryHashData(in ReadOnlySequence<byte>, Span<byte>, out int)
Computes the BLAKE2s hash of source using the default output size (32 bytes)
and writes it into destination.
public static bool TryHashData(in ReadOnlySequence<byte> source, Span<byte> destination, out int bytesWritten)
Parameters
sourceReadOnlySequence<byte>The (possibly multi-segment) input sequence to hash.
destinationSpan<byte>The buffer to receive the hash value. Must be at least MaxHashSizeBytes bytes.
bytesWrittenintWhen this method returns, the number of bytes written into
destination.
Returns
TryHashData(ReadOnlySpan<byte>, Span<byte>, out int)
Computes the BLAKE2s hash of source using the default output size (32 bytes)
and writes it into destination.
public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
Parameters
sourceReadOnlySpan<byte>The input data to hash.
destinationSpan<byte>The buffer to receive the hash value. Must be at least MaxHashSizeBytes bytes.
bytesWrittenintWhen this method returns, the number of bytes written into
destination.
Returns
TryHashFinal(Span<byte>, out int)
When overridden in a derived class, finalizes the hash computation and writes the result into the provided buffer.
protected override bool TryHashFinal(Span<byte> destination, out int bytesWritten)
Parameters
destinationSpan<byte>The target buffer to write the hash to.
bytesWrittenintThe number of bytes written into the buffer.
Returns
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.