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