Table of Contents

Class HMACSHA256

Namespace
System.Security.Cryptography
Assembly
nanoFramework.Azure.Devices.Client.dll

Computes a Hash-based Message Authentication Code (HMAC) by using the System.Security.Cryptography.SHA256 hash function.

public class HMACSHA256
Inheritance
HMACSHA256
Inherited Members
Extension Methods

Constructors

HMACSHA256()

Initializes a new instance of the HMACSHA256 class with a randomly generated key.

public HMACSHA256()

Remarks

HMACSHA256 is a type of keyed hash algorithm that is constructed from the SHA-256 hash function and used as a Hash-based Message Authentication Code (HMAC). The HMAC process mixes a secret key with the message data, hashes the result with the hash function, mixes that hash value with the secret key again, and then applies the hash function a second time. The output hash is 256 bits in length.

This constructor uses a 64-byte, randomly generated key.

HMACSHA256(byte[])

Initializes a new instance of the System.Security.Cryptography.HMACSHA256 class with the specified key data.

public HMACSHA256(byte[] key)

Parameters

key byte[]

The secret key for System.Security.Cryptography.HMACSHA256 encryption. The key can be any length. However, the recommended size is 64 bytes max.

Properties

Hash

Gets the value of the computed hash code.

public byte[] Hash { get; }

Property Value

byte[]

The current value of the computed hash code.

Exceptions

ObjectDisposedException

The object has already been disposed.

Key

Gets or sets the key to use in the HMAC calculation.

public byte[] Key { get; set; }

Property Value

byte[]

Methods

ComputeHash(byte[])

Computes the hash value for the specified byte array.

public byte[] ComputeHash(byte[] buffer)

Parameters

buffer byte[]

The input to compute the hash code for.

Returns

byte[]

The computed hash code.

Exceptions

ArgumentNullException

buffer is null.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected void Dispose(bool disposing)

Parameters

disposing bool

HashData(byte[], byte[])

Computes the HMAC of data using the SHA256 algorithm.

public static byte[] HashData(byte[] key, byte[] source)

Parameters

key byte[]

The HMAC key.

source byte[]

The data to HMAC.

Returns

byte[]

The HMAC of the data.

Exceptions

ArgumentNullException

key or source is null.