HashAlgorithm.Create 方法
定义
创建哈希算法实现的实例。Creates an instance of an implementation of a hash algorithm.
重载
| Create() |
已过时。
创建哈希算法的默认实现的实例。Creates an instance of the default implementation of a hash algorithm. |
| Create(String) |
创建哈希算法的指定实现的实例。Creates an instance of the specified implementation of a hash algorithm. |
Create()
注意
The default implementation of this cryptography algorithm is not supported
创建哈希算法的默认实现的实例。Creates an instance of the default implementation of a hash algorithm.
public:
static System::Security::Cryptography::HashAlgorithm ^ Create();
[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 ();
public static System.Security.Cryptography.HashAlgorithm Create ();
[<System.Obsolete("The default implementation of this cryptography algorithm is not supported", DiagnosticId="SYSLIB0007", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member Create : unit -> System.Security.Cryptography.HashAlgorithm
static member Create : unit -> System.Security.Cryptography.HashAlgorithm
Public Shared Function Create () As HashAlgorithm
返回
一个新的 SHA1CryptoServiceProvider 实例,除非已使用更改默认设置。A new SHA1CryptoServiceProvider instance, unless the default settings have been changed using the .
- 属性
例外
.NET Core 2.0 - 3.1 和 .NET 5.0 及更高版本:在所有情况下。.NET Core 2.0 - 3.1 and .NET 5.0 and later: In all cases.
注解
此方法在 .NET 5.0 及更高版本中已过时。This method is obsolete in .NET 5.0 and later versions.
默认情况下,此重载使用 SHA1CryptoServiceProvider 哈希算法的实现。By default, this overload uses the SHA1CryptoServiceProvider implementation of a hash algorithm. 如果要指定其他实现,请使用 Create(String) 重载,该重载使您可以改为指定算法名称。If you want to specify a different implementation, use the Create(String) overload, which lets you specify an algorithm name, instead. 加密配置系统定义的默认实现 HashAlgorithm 。The cryptography configuration system defines the default implementation of HashAlgorithm.
由于 SHA1 出现冲突问题,Microsoft 建议使用基于 SHA256 或更好的安全模型。Due to collision problems with SHA1, Microsoft recommends a security model based on SHA256 or better.
适用于
Create(String)
创建哈希算法的指定实现的实例。Creates an instance of the specified implementation of a hash algorithm.
public:
static System::Security::Cryptography::HashAlgorithm ^ Create(System::String ^ hashName);
public static System.Security.Cryptography.HashAlgorithm? Create (string hashName);
public static System.Security.Cryptography.HashAlgorithm Create (string hashName);
static member Create : string -> System.Security.Cryptography.HashAlgorithm
Public Shared Function Create (hashName As String) As HashAlgorithm
参数
- hashName
- String
要使用的哈希算法的实现。The hash algorithm implementation to use. 下表显示 hashName 参数的有效值以及它们映射到的算法。The following table shows the valid values for the hashName parameter and the algorithms they map to.
| 参数值Parameter value | 实现为其类型参数Implements |
|---|---|
| SHASHA | SHA1CryptoServiceProvider |
| SHA1SHA1 | SHA1CryptoServiceProvider |
| System.Security.Cryptography.SHA1System.Security.Cryptography.SHA1 | SHA1CryptoServiceProvider |
| System.Security.Cryptography.HashAlgorithmSystem.Security.Cryptography.HashAlgorithm | SHA1CryptoServiceProvider |
| MD5MD5 | MD5CryptoServiceProvider |
| System.Security.Cryptography.MD5System.Security.Cryptography.MD5 | MD5CryptoServiceProvider |
| SHA256SHA256 | SHA256Managed |
| SHA-256SHA-256 | SHA256Managed |
| System.Security.Cryptography.SHA256System.Security.Cryptography.SHA256 | SHA256Managed |
| SHA384SHA384 | SHA384Managed |
| SHA-384SHA-384 | SHA384Managed |
| System.Security.Cryptography.SHA384System.Security.Cryptography.SHA384 | SHA384Managed |
| SHA512SHA512 | SHA512Managed |
| SHA-512SHA-512 | SHA512Managed |
| System.Security.Cryptography.SHA512System.Security.Cryptography.SHA512 | SHA512Managed |
返回
所指定哈希算法,或 null 的新实例,如果 hashName 不是有效哈希算法。A new instance of the specified hash algorithm, or null if hashName is not a valid hash algorithm.