Rediger

Del via


HMACSHA1 Constructors

Definition

Initializes a new instance of the HMACSHA1 class.

Overloads

HMACSHA1()

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

HMACSHA1(Byte[], Boolean)
Obsolete.

Initializes a new instance of the HMACSHA1 class with the specified key data and a value that specifies whether to use the managed version of the SHA1 algorithm.

HMACSHA1(Byte[])

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

HMACSHA1()

Source:
HMACSHA1.cs
Source:
HMACSHA1.cs
Source:
HMACSHA1.cs

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

public:
 HMACSHA1();
public HMACSHA1 ();
Public Sub New ()

Remarks

HMACSHA1 is a type of keyed hash algorithm that is constructed from the SHA1 hash function and used as an HMAC, or hash-based message authentication code. 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 160 bits (20 bytes) in length.

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

Due to collision problems with SHA1, Microsoft recommends SHA256.

See also

Applies to

HMACSHA1(Byte[], Boolean)

Source:
HMACSHA1.cs
Source:
HMACSHA1.cs
Source:
HMACSHA1.cs

Caution

HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter.

Initializes a new instance of the HMACSHA1 class with the specified key data and a value that specifies whether to use the managed version of the SHA1 algorithm.

public:
 HMACSHA1(cli::array <System::Byte> ^ key, bool useManagedSha1);
public HMACSHA1 (byte[] key, bool useManagedSha1);
[System.Obsolete("HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter.", DiagnosticId="SYSLIB0030", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public HMACSHA1 (byte[] key, bool useManagedSha1);
new System.Security.Cryptography.HMACSHA1 : byte[] * bool -> System.Security.Cryptography.HMACSHA1
[<System.Obsolete("HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter.", DiagnosticId="SYSLIB0030", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.HMACSHA1 : byte[] * bool -> System.Security.Cryptography.HMACSHA1
Public Sub New (key As Byte(), useManagedSha1 As Boolean)

Parameters

key
Byte[]

The secret key for HMAC computation. The key can be any length, but if it is more than 64 bytes long, it is hashed (using SHA-1) to derive a 20-byte key. Therefore, the recommended size of the secret key is 64 bytes.

useManagedSha1
Boolean

true to use the managed implementation of the SHA1 algorithm (the SHA1Managed class); false to use the unmanaged implementation (the SHA1CryptoServiceProvider class).

Attributes

Remarks

Due to collision problems with SHA1, Microsoft recommends a security model based on SHA256 or better.

Applies to

HMACSHA1(Byte[])

Source:
HMACSHA1.cs
Source:
HMACSHA1.cs
Source:
HMACSHA1.cs

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

public:
 HMACSHA1(cli::array <System::Byte> ^ key);
public:
 HMACSHA1(cli::array <System::Byte> ^ rgbKey);
public HMACSHA1 (byte[] key);
public HMACSHA1 (byte[] rgbKey);
new System.Security.Cryptography.HMACSHA1 : byte[] -> System.Security.Cryptography.HMACSHA1
new System.Security.Cryptography.HMACSHA1 : byte[] -> System.Security.Cryptography.HMACSHA1
Public Sub New (key As Byte())
Public Sub New (rgbKey As Byte())

Parameters

keyrgbKey
Byte[]

The secret key for HMACSHA1 encryption. The key can be any length, but if it is more than 64 bytes long it is hashed (using SHA-1) to derive a 64-byte key. Therefore, the recommended size of the secret key is 64 bytes.

Exceptions

The key parameter is null.

Examples

For an example of how to use this constructor, see the HMACSHA1 class.

Remarks

HMACSHA1 is a type of keyed hash algorithm that is constructed from the SHA1 hash function and used as an HMAC, or hash-based message authentication code. 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 160 bits (20 bytes) in length.

Note

This constructor creates an unmanaged instance of the algorithm by using the SHA1CryptoServiceProvider class.

Due to collision problems with SHA1, Microsoft recommends a security model based on SHA256 or better.

See also

Applies to