HMACSHA1 构造函数

定义

初始化 HMACSHA1 类的新实例。

重载

HMACSHA1()

使用随机生成的密钥初始化 HMACSHA1 类的新实例。

HMACSHA1(Byte[], Boolean)
已过时。

使用指定的密钥数据和一个指定是否使用 SHA1 算法托管版本的值,来初始化 HMACSHA1 类的新实例。

HMACSHA1(Byte[])

使用指定的密钥数据初始化 HMACSHA1 类的新实例。

HMACSHA1()

使用随机生成的密钥初始化 HMACSHA1 类的新实例。

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

注解

HMACSHA1 是从 SHA1 哈希函数构造并用作 HMAC 或基于哈希的消息身份验证代码的键控哈希算法。 HMAC 进程将密钥与消息数据混合,使用哈希函数对结果进行哈希处理,将哈希值与密钥再次混合,然后再次应用哈希函数。 输出哈希长度为 160 位, (20 字节) 。

此构造函数使用 64 字节随机生成的密钥。

由于与 SHA1 冲突,Microsoft 建议使用 SHA256。

另请参阅

适用于

HMACSHA1(Byte[], Boolean)

注意

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

使用指定的密钥数据和一个指定是否使用 SHA1 算法托管版本的值,来初始化 HMACSHA1 类的新实例。

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)

参数

key
Byte[]

HMACSHA1 加密的机密密钥。 密钥的长度不限,但如果该密钥超过 64 个字节,就会经过散列处理(使用 SHA-1)以派生一个 64 个字节的密钥。 因此,建议的密钥大小为 64 个字节。

useManagedSha1
Boolean

如果使用 SHA1 算法的托管实现(SHA1Managed 类),则为 true;如果使用非托管实现(SHA1CryptoServiceProvider 类),则为 false

属性

注解

由于 SHA1 出现冲突问题,Microsoft 建议使用基于 SHA256 或更好的安全模型。

适用于

HMACSHA1(Byte[])

使用指定的密钥数据初始化 HMACSHA1 类的新实例。

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())

参数

keyrgbKey
Byte[]

HMACSHA1 加密的机密密钥。 密钥的长度不限,但如果该密钥是 64 个字节,就会经过散列处理(使用 SHA-1)以派生一个 64 个字节的密钥。 因此,建议的密钥大小为 64 个字节。

例外

key 参数为 null

示例

有关如何使用此构造函数的示例,请参阅 HMACSHA1 该类。

注解

HMACSHA1 是从 SHA1 哈希函数构造并用作 HMAC 或基于哈希的消息身份验证代码的键控哈希算法。 HMAC 进程将密钥与消息数据混合,使用哈希函数对结果进行哈希处理,将哈希值与密钥再次混合,然后再次应用哈希函数。 输出哈希长度为 160 位, (20 字节) 。

备注

此构造函数使用 SHA1CryptoServiceProvider 类创建算法的非托管实例。

由于 SHA1 出现冲突问题,Microsoft 建议使用基于 SHA256 或更好的安全模型。

另请参阅

适用于