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 and hashes the result. The hash value is mixed with the secret key again, and then hashed a second time. The output hash is 512 bits in length.
An HMAC can be used to determine whether a message sent over a nonsecure 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 hash value as a single message. The receiver recalculates the hash value on the received message and checks that the computed HMAC matches the transmitted HMAC.
If the original and computed hash values match, the message is authenticated. If they do not match, either the data or the hash value has been changed. HMACs provide security against tampering because knowledge of the secret key is required to change the message and reproduce the correct hash value.
HMACSHA512 accepts keys of any size, and produces a hash sequence of length 512 bits.
.NET Framework 2.0 Considerations
In the .NET Framework version 2.0, the HMACSHA512 class produced results that were not consistent with other implementations of HMAC-SHA-512. The .NET Framework version 2.0 Service Pack 1 updates this class. However, the HMAC values it produces are inconsistent with the output of the .NET Framework 2.0 implementation of the class. To enable .NET Framework 2.0 SP1 applications to interact with .NET Framework 2.0 applications, the .NET Framework 2.0 SP1 introduces the following four changes to the HMACSHA512 class:
The ProduceLegacyHmacValues Boolean property supports the earlier implementation. When you set this property to true, the HMACSHA512 object produces values that match the values produced by the .NET Framework 2.0.
In some applications, it may be expensive or difficult to change the code. For these situations, .NET Framework 2.0 SP1 provides a configuration switch, legacyHMACMode, for the application’s .config file. This switch causes all HMAC objects created in the application to use the .NET Framework 2.0 calculation.
<configuration>
<runtime>
<legacyHMACMode enabled="1" />
</runtime>
</configuration>
To help debug any issues that arise when upgrading to the .NET Framework 2.0 SP1, the first time an instance of the HMACSHA512 class is created, a warning about the implementation changes is sent to the event log and to any attached debugger. If you set the legacyHMACMode configuration switch to use the .NET Framework 2.0 calculation, this message is not generated.
The .NET Framework 2.0 SP1 also introduces a second configuration switch, legacyHMACWarning, that lets you manually suppress the warning message for your application.
<configuration>
<runtime>
<legacyHMACWarning enabled="0" />
</runtime>
</configuration>
Note that these four changes affect only the HMACSHA384 and HMACSHA512 classes, and not the SHA256Managed class.