HashAlgorithm.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 algorithm.

Overloads

Create()
Obsolete.
Obsolete.

Creates an instance of the default implementation of a hash algorithm.

Create(String)
Obsolete.

Creates an instance of the specified implementation of a hash algorithm.

Create()

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

Caution

The default implementation of this cryptography algorithm is not supported.

Caution

The default implementation of this cryptography algorithm is not supported

Creates an instance of the default implementation of a hash algorithm.

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

Returns

A new SHA1CryptoServiceProvider instance, unless the default settings have been changed using the .

Attributes

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 SHA1CryptoServiceProvider implementation of a hash algorithm. If you want to specify a different implementation, use the Create(String) overload, which lets you specify an algorithm name, instead. The cryptography configuration system defines the default implementation of HashAlgorithm.

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

Applies to

.NET 10 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1 (5, 6, 7, 8, 9, 10)
.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

Caution

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

Creates an instance of the specified implementation of a hash algorithm.

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);
C#
public static System.Security.Cryptography.HashAlgorithm Create(string hashName);

Parameters

hashName
String

The hash algorithm implementation to use. The following table shows the valid values for the hashName parameter and the algorithms they map to.

Parameter value Implements
SHA SHA1CryptoServiceProvider
SHA1 SHA1CryptoServiceProvider
System.Security.Cryptography.SHA1 SHA1CryptoServiceProvider
System.Security.Cryptography.HashAlgorithm SHA1CryptoServiceProvider
MD5 MD5CryptoServiceProvider
System.Security.Cryptography.MD5 MD5CryptoServiceProvider
SHA256 SHA256Managed
SHA-256 SHA256Managed
System.Security.Cryptography.SHA256 SHA256Managed
SHA384 SHA384Managed
SHA-384 SHA384Managed
System.Security.Cryptography.SHA384 SHA384Managed
SHA512 SHA512Managed
SHA-512 SHA512Managed
System.Security.Cryptography.SHA512 SHA512Managed

Returns

A new instance of the specified hash algorithm, or null if hashName is not a valid hash algorithm.

Attributes

Applies to

.NET 10 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6 (7, 8, 9, 10)
.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