Table of Contents

Class HMACSHA512

Namespace
System.Security.Cryptography
Assembly
nanoFramework.System.Security.Cryptography.dll

Computes a Hash-based Message Authentication Code (HMAC) by using the SHA512 hash function.

public class HMACSHA512 : IDisposable
Inheritance
HMACSHA512
Implements
Inherited Members
Extension Methods

Constructors

HMACSHA512()

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

public HMACSHA512()

Remarks

HMACSHA512 is a type of keyed hash algorithm that is constructed from the SHA-512 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 512 bits in length.

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

HMACSHA512(byte[])

Initializes a new instance of the HMACSHA512 class with the specified key data.

public HMACSHA512(byte[] key)

Parameters

key byte[]

The secret key for HMAC computation. The key can be any length. However, the recommended size is 128 bytes. If the key is more than 128 bytes long, it is hashed (using SHA-512) to derive a 64-byte key.

Remarks

HMACSHA512 is a type of keyed hash algorithm that is constructed from the SHA-512 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 512 bits in length.

Exceptions

ArgumentNullException

The key parameter is null.

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[]

The key to use in the HMAC calculation.

Remarks

This property is the key for the keyed hash algorithm.

A Hash-based Message Authentication Code (HMAC) can be used to determine whether a message sent over an insecure channel has been tampered with, provided that the sender and receiver share a secret key. The sender computes the hash value for the original data and sends both the original data and the HMAC as a single message. The receiver recomputes the hash value on the received message and checks that the computed hash value matches the transmitted hash value.

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

ObjectDisposedException

The object has already been disposed.

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 SHA512 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.