HMAC.Create Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates an instance of an implementation of a Hash-based Message Authentication Code (HMAC) .
Overloads
| Name | Description |
|---|---|
| Create() |
Creates an instance of the default implementation of a Hash-based Message Authentication Code (HMAC). |
| Create(String) |
Creates an instance of the specified implementation of a Hash-based Message Authentication Code (HMAC). |
Create()
Creates an instance of the default implementation of a Hash-based Message Authentication Code (HMAC).
public:
static System::Security::Cryptography::HMAC ^ Create();
public static System.Security.Cryptography.HMAC Create();
static member Create : unit -> System.Security.Cryptography.HMAC
Public Shared Function Create () As HMAC
Returns
A new SHA-1 instance, unless the default settings have been changed by using the <cryptoClass> element.
Exceptions
.NET Core 2.0 - 3.1 and .NET 5 and later: In all cases.
Remarks
This method is obsolete in .NET 5 and later versions.
By default, this overload uses the SHA-1 implementation of HMAC. If you want to specify a different implementation, use the Create(String) overload, which lets you specify an algorithm name, instead.
Due to collision problems with SHA-1, Microsoft recommends a security model based on SHA-256 or better.
Applies to
Create(String)
Creates an instance of the specified implementation of a Hash-based Message Authentication Code (HMAC).
public:
static System::Security::Cryptography::HMAC ^ Create(System::String ^ algorithmName);
public static System.Security.Cryptography.HMAC Create(string algorithmName);
static member Create : string -> System.Security.Cryptography.HMAC
Public Shared Function Create (algorithmName As String) As HMAC
Parameters
- algorithmName
- String
The HMAC implementation to use. The following table shows the valid values for the algorithmName parameter and the algorithms they map to.
| Parameter value | Implements |
|---|---|
| System.Security.Cryptography.HMAC | HMACSHA1 |
| System.Security.Cryptography.KeyedHashAlgorithm | HMACSHA1 |
| HMACMD5 | HMACMD5 |
| System.Security.Cryptography.HMACMD5 | HMACMD5 |
| HMACRIPEMD160 | HMACRIPEMD160 |
| System.Security.Cryptography.HMACRIPEMD160 | HMACRIPEMD160 |
| HMACSHA1 | HMACSHA1 |
| System.Security.Cryptography.HMACSHA1 | HMACSHA1 |
| HMACSHA256 | HMACSHA256 |
| System.Security.Cryptography.HMACSHA256 | HMACSHA256 |
| HMACSHA384 | HMACSHA384 |
| System.Security.Cryptography.HMACSHA384 | HMACSHA384 |
| HMACSHA512 | HMACSHA512 |
| System.Security.Cryptography.HMACSHA512 | HMACSHA512 |
| MACTripleDES | MACTripleDES |
| System.Security.Cryptography.MACTripleDES | MACTripleDES |
Returns
A new instance of the specified HMAC implementation.
Remarks
HMAC supports a number of hash algorithms, including MD5, SHA-1, SHA-256, and RIPEMD160. For the full list, see the supported values for the algorithmName parameter.
Due to collision problems with MD5 and SHA-1, Microsoft recommends a security model based on SHA-256 or better.