CryptographicOperations.HmacData Method

Definition

Overloads

HmacData(HashAlgorithmName, ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>)

Source:
CryptographicOperations.cs

Computes the HMAC of data.

C#
public static int HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, ReadOnlySpan<byte> key, ReadOnlySpan<byte> source, Span<byte> destination);

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the HMAC.

key
ReadOnlySpan<Byte>

The secret key. The key can be any length.

source
ReadOnlySpan<Byte>

The data to compute the HMAC over.

destination
Span<Byte>

The buffer to receive the HMAC value.

Returns

The total number of bytes written to destination.

Exceptions

The buffer in destination is too small to hold the calculated hash size.

-or-

hashAlgorithm has a Name that is empty.

hashAlgorithm has a Name that is null.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

HmacData(HashAlgorithmName, ReadOnlySpan<Byte>, Stream, Span<Byte>)

Source:
CryptographicOperations.cs

Computes the HMAC of a stream.

C#
public static int HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, ReadOnlySpan<byte> key, System.IO.Stream source, Span<byte> destination);

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the HMAC.

key
ReadOnlySpan<Byte>

The secret key. The key can be any length.

source
Stream

The data to compute the HMAC over.

destination
Span<Byte>

The buffer to receive the HMAC value.

Returns

The total number of bytes written to destination.

Exceptions

source is null.

-or-

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

-or-

source does not support reading.

-or-

The buffer in destination is too small to hold the calculated HMAC size.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

HmacData(HashAlgorithmName, ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)

Source:
CryptographicOperations.cs

Computes the HMAC of data.

C#
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, ReadOnlySpan<byte> key, ReadOnlySpan<byte> source);

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the HMAC.

key
ReadOnlySpan<Byte>

The secret key. The key can be any length.

source
ReadOnlySpan<Byte>

The data to compute the HMAC over.

Returns

Byte[]

The HMAC of the data.

Exceptions

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

HmacData(HashAlgorithmName, Byte[], Stream)

Source:
CryptographicOperations.cs

Computes the HMAC of a stream.

C#
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, System.IO.Stream source);

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the HMAC.

key
Byte[]

The secret key. The key can be any length.

source
Stream

The data to compute the HMAC over.

Returns

Byte[]

The HMAC of the data.

Exceptions

key or source is null.

-or-

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

-or-

source does not support reading.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

HmacData(HashAlgorithmName, Byte[], Byte[])

Source:
CryptographicOperations.cs

Computes the HMAC of data.

C#
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, byte[] source);

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the HMAC.

key
Byte[]

The secret key. The key can be any length.

source
Byte[]

The data to compute the HMAC over.

Returns

Byte[]

The HMAC of the data.

Exceptions

key or source is null.

-or-

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

HmacData(HashAlgorithmName, ReadOnlySpan<Byte>, Stream)

Source:
CryptographicOperations.cs

Computes the HMAC of a stream.

C#
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, ReadOnlySpan<byte> key, System.IO.Stream source);

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the HMAC.

key
ReadOnlySpan<Byte>

The secret key. The key can be any length.

source
Stream

The data to compute the HMAC over.

Returns

Byte[]

The HMAC of the data.

Exceptions

source is null.

-or-

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

-or-

source does not support reading.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10