HashAlgorithm.Create 方法

定义

创建哈希算法实现的实例。

重载

Create()
已过时.
已过时.

创建哈希算法的默认实现的实例。

Create(String)
已过时.

创建哈希算法的指定实现的实例。

Create()

Source:
HashAlgorithm.cs
Source:
HashAlgorithm.cs
Source:
HashAlgorithm.cs

注意

The default implementation of this cryptography algorithm is not supported

注意

The default implementation of this cryptography algorithm is not supported.

创建哈希算法的默认实现的实例。

C#
[System.Obsolete("The default implementation of this cryptography algorithm is not supported", DiagnosticId="SYSLIB0007", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.HashAlgorithm Create();
C#
[System.Obsolete("The default implementation of this cryptography algorithm is not supported.", DiagnosticId="SYSLIB0007", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.HashAlgorithm Create();
C#
public static System.Security.Cryptography.HashAlgorithm Create();

返回

一个新的 SHA1CryptoServiceProvider 实例,除非已使用更改默认设置。

属性

例外

.NET Core 2.0 - 3.1 和 .NET 5 及更高版本:在所有情况下。

注解

此方法在 .NET 5 及更高版本中已过时。

默认情况下,此重载使用 SHA1CryptoServiceProvider 哈希算法的 实现。 如果要指定其他实现,请使用 Create(String) 重载,以便指定算法名称。 加密配置系统定义 的默认实现 HashAlgorithm

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

适用于

.NET 9 和其他版本
产品 版本 (已过时)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1 (5, 6, 7, 8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Create(String)

Source:
HashAlgorithm.cs
Source:
HashAlgorithm.cs
Source:
HashAlgorithm.cs

注意

Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead.

创建哈希算法的指定实现的实例。

C#
public static System.Security.Cryptography.HashAlgorithm? Create(string hashName);
C#
[System.Obsolete("Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead.", DiagnosticId="SYSLIB0045", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.HashAlgorithm? Create(string hashName);
C#
public static System.Security.Cryptography.HashAlgorithm Create(string hashName);

参数

hashName
String

要使用的哈希算法的实现。 下表显示 hashName 参数的有效值以及它们映射到的算法。

参数值 实现为其类型参数
SHASHA1CryptoServiceProvider
SHA1SHA1CryptoServiceProvider
System.Security.Cryptography.SHA1SHA1CryptoServiceProvider
System.Security.Cryptography.HashAlgorithmSHA1CryptoServiceProvider
MD5MD5CryptoServiceProvider
System.Security.Cryptography.MD5MD5CryptoServiceProvider
SHA256SHA256Managed
SHA-256SHA256Managed
System.Security.Cryptography.SHA256SHA256Managed
SHA384SHA384Managed
SHA-384SHA384Managed
System.Security.Cryptography.SHA384SHA384Managed
SHA512SHA512Managed
SHA-512SHA512Managed
System.Security.Cryptography.SHA512SHA512Managed

返回

所指定哈希算法,或 null 的新实例,如果 hashName 不是有效哈希算法。

属性

适用于

.NET 9 和其他版本
产品 版本 (已过时)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6 (7, 8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1