AsymmetricAlgorithm.Create Method

Definition

Creates a cryptographic object used to perform the asymmetric algorithm.

Overloads

Create()
Obsolete.
Obsolete.

Creates a default cryptographic object used to perform the asymmetric algorithm.

Create(String)
Obsolete.

Creates an instance of the specified implementation of an asymmetric algorithm.

Create()

Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs

Caution

The default implementation of this cryptography algorithm is not supported

Caution

The default implementation of this cryptography algorithm is not supported.

Creates a default cryptographic object used to perform the asymmetric 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.AsymmetricAlgorithm 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.AsymmetricAlgorithm Create();
C#
public static System.Security.Cryptography.AsymmetricAlgorithm Create();

Returns

A new RSACryptoServiceProvider instance, unless the default settings have been changed with the <cryptoClass> element.

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.

Example

The following code example demonstrates how to implement the Create method in an extended class. This code example is part of a larger example provided for the AsymmetricAlgorithm class.

C#
// The create function attempts to create a CustomCrypto object using
// the assembly name. This functionality requires modification of the
// machine.config file. Add the following section to the configuration
// element and modify the values of the cryptoClass to reflect what is
// installed in your machines GAC.
//        <cryptoClass CustomCrypto="Contoso.CustomCrypto, 
//          CustomCrypto, 
//          Culture=neutral, 
//          PublicKeyToken=fdb9f9c4851028bf, 
//          Version=1.0.1448.27640" />
//      <nameEntry name="Contoso.CustomCrypto" class="CustomCrypto" />
//      <nameEntry name="CustomCrypto" class="CustomCrypto" />
new static public CustomCrypto Create() 
{
    return Create("CustomCrypto");
}

See also

Applies to

.NET 9 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)
.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:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.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 an asymmetric algorithm.

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

Parameters

algName
String

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

Parameter value Implements
System.Security.Cryptography.AsymmetricAlgorithm AsymmetricAlgorithm
RSA RSA
System.Security.Cryptography.RSA RSA
DSA DSA
System.Security.Cryptography.DSA DSA
ECDsa ECDsa
ECDsaCng ECDsaCng
System.Security.Cryptography.ECDsaCng ECDsaCng
ECDH ECDiffieHellman
ECDiffieHellman ECDiffieHellman
ECDiffieHellmanCng ECDiffieHellmanCng
System.Security.Cryptography.ECDiffieHellmanCng ECDiffieHellmanCng

Returns

A new instance of the specified asymmetric algorithm implementation.

Attributes

Examples

The following code example demonstrates how to implement the Create method in an extended class. This code example is part of a larger example provided for the AsymmetricAlgorithm class.

C#
// The create function attempts to create a CustomCrypto object using
// the assembly name. This functionality requires modification of the
// machine.config file. Add the following section to the configuration
// element and modify the values of the cryptoClass to reflect what is
// installed in your machines GAC.
//       <cryptoClass CustomCrypto="Contoso.CustomCrypto, 
//         CustomCrypto, 
//         Culture=neutral, 
//         PublicKeyToken=fdb9f9c4851028bf, 
//         Version=1.0.1448.27640" />
//     <nameEntry name="Contoso.CustomCrypto" class="CustomCrypto" />
//     <nameEntry name="CustomCrypto" class="CustomCrypto" />
new static public CustomCrypto Create(String algorithmName) 
{
    return (CustomCrypto) CryptoConfig.CreateFromName(algorithmName);
}

See also

Applies to

.NET 9 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)
.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