Class CryptoHmacSha512_256
- Namespace
- LibSodium
- Assembly
- LibSodium.Net.dll
Computes and verifies HMAC-SHA-512/256 message authentication codes.
public static class CryptoHmacSha512_256
- Inheritance
-
CryptoHmacSha512_256
- Inherited Members
Fields
KeyLen
Length of the secret key in bytes (32).
public static readonly int KeyLen
Field Value
MacLen
Length of the HMAC output in bytes (32).
public static readonly int MacLen
Field Value
Methods
ComputeMac(SecureMemory<byte>, Stream, Span<byte>)
Computes an HMAC-SHA-512/256 authentication code from a stream.
public static void ComputeMac(SecureMemory<byte> key, Stream messageStream, Span<byte> mac)
Parameters
key
SecureMemory<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
Span<byte>A buffer to receive the 32-byte MAC.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.- LibSodiumException
Thrown if the MAC computation fails internally.
ComputeMac(SecureMemory<byte>, ReadOnlySpan<byte>, Span<byte>)
Computes an HMAC-SHA-512/256 authentication code for the given message.
public static int ComputeMac(SecureMemory<byte> key, ReadOnlySpan<byte> message, Span<byte> mac)
Parameters
key
SecureMemory<byte>A 32-byte secret key.
message
ReadOnlySpan<byte>The message to authenticate.
mac
Span<byte>A buffer to receive the 32-byte MAC.
Returns
- int
The length of the MAC written (always 32).
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.- LibSodiumException
Thrown if the MAC computation fails internally.
ComputeMac(ReadOnlySpan<byte>, Stream, Span<byte>)
Computes an HMAC-SHA-512/256 authentication code from a stream.
public static void ComputeMac(ReadOnlySpan<byte> key, Stream messageStream, Span<byte> mac)
Parameters
key
ReadOnlySpan<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
Span<byte>A buffer to receive the 32-byte MAC.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.- LibSodiumException
Thrown if the MAC computation fails internally.
ComputeMac(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)
Computes an HMAC-SHA-512/256 authentication code for the given message.
public static int ComputeMac(ReadOnlySpan<byte> key, ReadOnlySpan<byte> message, Span<byte> mac)
Parameters
key
ReadOnlySpan<byte>A 32-byte secret key.
message
ReadOnlySpan<byte>The message to authenticate.
mac
Span<byte>A buffer to receive the 32-byte MAC.
Returns
- int
The length of the MAC written (always 32).
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.- LibSodiumException
Thrown if the MAC computation fails internally.
ComputeMacAsync(SecureMemory<byte>, Stream, Memory<byte>, CancellationToken)
Asynchronously computes an HMAC-SHA-512/256 authentication code from a stream.
public static Task ComputeMacAsync(SecureMemory<byte> key, Stream messageStream, Memory<byte> mac, CancellationToken cancellationToken = default)
Parameters
key
SecureMemory<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
Memory<byte>A buffer to receive the 32-byte MAC.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.- LibSodiumException
Thrown if the MAC computation fails internally.
ComputeMacAsync(ReadOnlyMemory<byte>, Stream, Memory<byte>, CancellationToken)
Asynchronously computes an HMAC-SHA-512/256 authentication code from a stream.
public static Task ComputeMacAsync(ReadOnlyMemory<byte> key, Stream messageStream, Memory<byte> mac, CancellationToken cancellationToken = default)
Parameters
key
ReadOnlyMemory<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
Memory<byte>A buffer to receive the 32-byte MAC.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.- LibSodiumException
Thrown if the MAC computation fails internally.
CreateIncrementalMac(SecureMemory<byte>)
Creates an incremental hash object using the HMAC-SHA512/256 algorithm.
public static ICryptoIncrementalOperation CreateIncrementalMac(SecureMemory<byte> key)
Parameters
key
SecureMemory<byte>The cryptographic key (64 bytes) to use for the HMAC-SHA512/256 computation.
Returns
- ICryptoIncrementalOperation
An ICryptoIncrementalOperation instance that allows incremental computation of the HMAC-SHA512/256 hash.
Remarks
The returned ICryptoIncrementalOperation can be used to compute the HMAC-SHA512/256 hash incrementally by processing data in chunks.
CreateIncrementalMac(ReadOnlySpan<byte>)
Creates an incremental hash object using the HMAC-SHA512/256 algorithm.
public static ICryptoIncrementalOperation CreateIncrementalMac(ReadOnlySpan<byte> key)
Parameters
key
ReadOnlySpan<byte>The cryptographic key (64 bytes) to use for the HMAC-SHA512/256 computation.
Returns
- ICryptoIncrementalOperation
An ICryptoIncrementalOperation instance that allows incremental computation of the HMAC-SHA512/256 hash.
Remarks
The returned ICryptoIncrementalOperation can be used to compute the HMAC-SHA512/256 hash incrementally by processing data in chunks.
GenerateKey(SecureMemory<byte>)
Generates a random 32-byte key suitable for HMAC-SHA-512/256.
public static void GenerateKey(SecureMemory<byte> key)
Parameters
key
SecureMemory<byte>A buffer to receive the generated key (must be 32 bytes).
GenerateKey(Span<byte>)
Generates a random 32-byte key suitable for HMAC-SHA-512/256.
public static void GenerateKey(Span<byte> key)
Parameters
VerifyMac(SecureMemory<byte>, Stream, ReadOnlySpan<byte>)
Verifies an HMAC-SHA-512/256 authentication code from a stream.
public static bool VerifyMac(SecureMemory<byte> key, Stream messageStream, ReadOnlySpan<byte> mac)
Parameters
key
SecureMemory<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
ReadOnlySpan<byte>The expected 32-byte MAC.
Returns
- bool
true
if the MAC is valid; otherwise,false
.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.
VerifyMac(SecureMemory<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Verifies an HMAC-SHA-512/256 authentication code against a given message.
public static bool VerifyMac(SecureMemory<byte> key, ReadOnlySpan<byte> message, ReadOnlySpan<byte> mac)
Parameters
key
SecureMemory<byte>A 32-byte secret key.
message
ReadOnlySpan<byte>The message to verify.
mac
ReadOnlySpan<byte>The expected 32-byte MAC.
Returns
- bool
true
if the MAC is valid; otherwise,false
.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.
VerifyMac(ReadOnlySpan<byte>, Stream, ReadOnlySpan<byte>)
Verifies an HMAC-SHA-512/256 authentication code from a stream.
public static bool VerifyMac(ReadOnlySpan<byte> key, Stream messageStream, ReadOnlySpan<byte> mac)
Parameters
key
ReadOnlySpan<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
ReadOnlySpan<byte>The expected 32-byte MAC.
Returns
- bool
true
if the MAC is valid; otherwise,false
.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.
VerifyMac(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Verifies an HMAC-SHA-512/256 authentication code against a given message.
public static bool VerifyMac(ReadOnlySpan<byte> key, ReadOnlySpan<byte> message, ReadOnlySpan<byte> mac)
Parameters
key
ReadOnlySpan<byte>A 32-byte secret key.
message
ReadOnlySpan<byte>The message to verify.
mac
ReadOnlySpan<byte>The expected 32-byte MAC.
Returns
- bool
true
if the MAC is valid; otherwise,false
.
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.
VerifyMacAsync(SecureMemory<byte>, Stream, ReadOnlyMemory<byte>, CancellationToken)
Asynchronously verifies an HMAC-SHA-512/256 authentication code from a stream.
public static Task<bool> VerifyMacAsync(SecureMemory<byte> key, Stream messageStream, ReadOnlyMemory<byte> mac, CancellationToken cancellationToken = default)
Parameters
key
SecureMemory<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
ReadOnlyMemory<byte>The expected 32-byte MAC.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.
VerifyMacAsync(ReadOnlyMemory<byte>, Stream, ReadOnlyMemory<byte>, CancellationToken)
Asynchronously verifies an HMAC-SHA-512/256 authentication code from a stream.
public static Task<bool> VerifyMacAsync(ReadOnlyMemory<byte> key, Stream messageStream, ReadOnlyMemory<byte> mac, CancellationToken cancellationToken = default)
Parameters
key
ReadOnlyMemory<byte>A 32-byte secret key.
messageStream
StreamA stream containing the message.
mac
ReadOnlyMemory<byte>The expected 32-byte MAC.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
Exceptions
- ArgumentException
Thrown if
key
ormac
has an invalid length.