Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Security.​Cryptography.​AsymmetricAlgorithm

Assembly: System.Security.Cryptography

Inheritance: object → AsymmetricAlgorithm

Implemented Interfaces

Represents the abstract base class from which all implementations of asymmetric algorithms must inherit.

Fields and Constants

protected int
KeySizeValue
Represents the size, in bits, of the key modulus used by the asymmetric algorithm.
protected KeySizes[]
LegalKeySizesValue
Specifies the key sizes that are supported by the asymmetric algorithm.

Properties

public string
KeyExchangeAlgorithm
When overridden in a derived class, gets the name of the key exchange algorithm. Otherwise, throws an <see cref="T:System.NotImplementedException" /> .
public int
KeySize
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
public KeySizes[]
LegalKeySizes
Gets the key sizes that are supported by the asymmetric algorithm.
public string
SignatureAlgorithm
When implemented in a derived class, gets the name of the signature algorithm. Otherwise, always throws a <see cref="T:System.NotImplementedException" /> .

Methods

public void
Clear​()
Releases all resources used by the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
public static AsymmetricAlgorithm
Create​()
Creates a default cryptographic object used to perform the asymmetric algorithm.
Returns A new <see cref="T:System.Security.Cryptography.RSACryptoServiceProvider" /> instance, unless the default settings have been changed with the &lt;cryptoClass&gt; element.
public static AsymmetricAlgorithm
Create​(string algName)
Creates an instance of the specified implementation of an asymmetric algorithm.
Returns A new instance of the specified asymmetric algorithm implementation.
algName The asymmetric algorithm implementation to use. The following table shows the valid values for the <paramref name="algName" /> parameter and the algorithms they map to. <list type="table"> <listheader> <term> Parameter value</term> <description> Implements</description> </listheader> <item> <term> System.Security.Cryptography.AsymmetricAlgorithm</term> <description> <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> </description> </item> <item> <term> RSA</term> <description> <see cref="T:System.Security.Cryptography.RSA" /> </description> </item> <item> <term> System.Security.Cryptography.RSA</term> <description> <see cref="T:System.Security.Cryptography.RSA" /> </description> </item> <item> <term> DSA</term> <description> <see cref="T:System.Security.Cryptography.DSA" /> </description> </item> <item> <term> System.Security.Cryptography.DSA</term> <description> <see cref="T:System.Security.Cryptography.DSA" /> </description> </item> <item> <term> ECDsa</term> <description> <see cref="T:System.Security.Cryptography.ECDsa" /> </description> </item> <item> <term> ECDsaCng</term> <description> <see cref="T:System.Security.Cryptography.ECDsaCng" /> </description> </item> <item> <term> System.Security.Cryptography.ECDsaCng</term> <description> <see cref="T:System.Security.Cryptography.ECDsaCng" /> </description> </item> <item> <term> ECDH</term> <description> <see cref="T:System.Security.Cryptography.ECDiffieHellman" /> </description> </item> <item> <term> ECDiffieHellman</term> <description> <see cref="T:System.Security.Cryptography.ECDiffieHellman" /> </description> </item> <item> <term> ECDiffieHellmanCng</term> <description> <see cref="T:System.Security.Cryptography.ECDiffieHellmanCng" /> </description> </item> <item> <term> System.Security.Cryptography.ECDiffieHellmanCng</term> <description> <see cref="T:System.Security.Cryptography.ECDiffieHellmanCng" /> </description> </item> </list>
public void
Dispose​()
Releases all resources used by the current instance of the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
protected void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class and optionally releases the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
passwordBytes The bytes to use as a password when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password, PEM encoded.
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
passwordBytes The bytes to use as a password when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​char> password, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password, PEM encoded.
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportPkcs8PrivateKey​()
Exports the current key in the PKCS#8 PrivateKeyInfo format.
Returns A byte array containing the PKCS#8 PrivateKeyInfo representation of this key.
public string
ExportPkcs8PrivateKeyPem​()
Exports the current key in the PKCS#8 PrivateKeyInfo format, PEM encoded.
Returns A string containing the PEM-encoded PKCS#8 PrivateKeyInfo.
public byte[]
ExportSubjectPublicKeyInfo​()
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.
Returns A byte array containing the X.509 SubjectPublicKeyInfo representation of the public-key portion of this key.
public string
ExportSubjectPublicKeyInfoPem​()
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format, PEM encoded.
Returns A string containing the PEM-encoded X.509 SubjectPublicKeyInfo.
public void
FromXmlString​(string xmlString)
When overridden in a derived class, reconstructs an <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> object from an XML string. Otherwise, throws a <see cref="T:System.NotImplementedException" /> .
xmlString The XML string to use to reconstruct the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> object.
public void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, ReadOnlySpan<​byte> source, Int32& bytesRead)
public void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, ReadOnlySpan<​byte> source, Int32& bytesRead)
public void
ImportFromEncryptedPem​(ReadOnlySpan<​char> input, ReadOnlySpan<​byte> passwordBytes)
When overridden in a derived class, imports an encrypted RFC 7468 PEM-encoded key, replacing the keys for this object.
input The PEM text of the encrypted key to import.
passwordBytes The bytes to use as a password when decrypting the key material.
public void
ImportFromEncryptedPem​(ReadOnlySpan<​char> input, ReadOnlySpan<​char> password)
When overridden in a derived class, imports an encrypted RFC 7468 PEM-encoded key, replacing the keys for this object.
input The PEM text of the encrypted key to import.
password The password to use for decrypting the key material.
public void
ImportFromPem​(ReadOnlySpan<​char> input)
When overridden in a derived class, imports an RFC 7468 textually encoded key, replacing the keys for this object.
input The text of the PEM key to import.
public void
ImportPkcs8PrivateKey​(ReadOnlySpan<​byte> source, Int32& bytesRead)
public void
ImportSubjectPublicKeyInfo​(ReadOnlySpan<​byte> source, Int32& bytesRead)
public string
ToXmlString​(bool includePrivateParameters)
When overridden in a derived class, creates and returns an XML string representation of the current <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> object. Otherwise, throws a <see cref="T:System.NotImplementedException" /> .
Returns An XML string encoding of the current <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> object.
includePrivateParameters <see langword="true" /> to include private parameters; otherwise, <see langword="false" /> .
public bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters, Span<​char> destination, Int32& charsWritten)
public bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​char> password, PbeParameters pbeParameters, Span<​char> destination, Int32& charsWritten)
public bool
TryExportPkcs8PrivateKey​(Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportPkcs8PrivateKeyPem​(Span<​char> destination, Int32& charsWritten)
public bool
TryExportSubjectPublicKeyInfo​(Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportSubjectPublicKeyInfoPem​(Span<​char> destination, Int32& charsWritten)
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object