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.​RSACng
Assembly: System.Security.Cryptography
Inheritance: object → AsymmetricAlgorithm → RSA → RSACng
Provides a Cryptography Next Generation (CNG) implementation of the RSA algorithm.
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
CngKey
Key
Gets the key that will be used by the <see cref="T:System.Security.Cryptography.RSACng" /> object for any cryptographic operation that it performs.
public
KeySizes[]
LegalKeySizes
Gets the key sizes, in bits, that are supported by this implementation of RSA.
public
string
KeyExchangeAlgorithm
Gets the name of the key exchange algorithm available with this implementation of <see cref="T:System.Security.Cryptography.RSA" /> .
public
string
SignatureAlgorithm
Gets the name of the signature algorithm available with this implementation of <see cref="T:System.Security.Cryptography.RSA" /> .
public
int
KeySize
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
Methods
public
byte[]
Decrypt​(byte[] data,
RSAEncryptionPadding padding)
data
The data to decrypt.
padding
The padding mode.
Returns The decrypted data.
Decrypts input data using the specified padding mode.
protected
void
Dispose​(bool disposing)
public
byte[]
Encrypt​(byte[] data,
RSAEncryptionPadding padding)
data
The data to encrypt.
padding
The padding mode.
Returns The encrypted data.
Encrypts the input data using the specified padding.
public
byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters)
public
byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 password,
PbeParameters pbeParameters)
public
RSAParameters
ExportParameters​(bool includePrivateParameters)
includePrivateParameters
<see langword="true" /> to include private parameters; otherwise, <see langword="false" /> .
Returns The key used by the RSA object.
Exports the key used by the RSA object into a <see cref="T:System.Security.Cryptography.RSAParameters" /> object.
public
void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 passwordBytes,
ReadOnlySpan`1 source,
Int32& bytesRead)
public
void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 password,
ReadOnlySpan`1 source,
Int32& bytesRead)
public
void
ImportParameters​(RSAParameters parameters)
parameters
The RSA parameters.
Replaces the existing key that the current instance is working with by creating a new <see cref="T:System.Security.Cryptography.CngKey" /> for the parameters structure.
public
byte[]
SignHash​(byte[] hash,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
hash
The hash to sign.
hashAlgorithm
The hash algorithm name.
padding
The padding mode.
Returns The signed data.
Signs data that was hashed by using the specified hashing algorithm and padding mode.
public
bool
TryDecrypt​(ReadOnlySpan`1 data,
Span`1 destination,
RSAEncryptionPadding padding,
Int32& bytesWritten)
public
bool
TryEncrypt​(ReadOnlySpan`1 data,
Span`1 destination,
RSAEncryptionPadding padding,
Int32& bytesWritten)
public
bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters,
Span`1 destination,
Int32& bytesWritten)
public
bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 password,
PbeParameters pbeParameters,
Span`1 destination,
Int32& bytesWritten)
public
bool
TrySignHash​(ReadOnlySpan`1 hash,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding,
Int32& bytesWritten)
public
bool
VerifyHash​(byte[] hash,
byte[] signature,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
hash
The hash to verify.
signature
The signature of the data.
hashAlgorithm
The hash algorithm name.
padding
The padding mode.
Returns <see langword="true" /> if the signature verifies for the hash; otherwise, <see langword="false" /> .
Verifies data that was signed and already hashed with the specified algorithm and padding mode.
public
bool
VerifyHash​(ReadOnlySpan`1 hash,
ReadOnlySpan`1 signature,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
public
byte[]
Decrypt​(ReadOnlySpan`1 data,
RSAEncryptionPadding padding)
Inherited from RSA
public
int
Decrypt​(ReadOnlySpan`1 data,
Span`1 destination,
RSAEncryptionPadding padding)
Inherited from RSA
public
byte[]
DecryptValue​(byte[] rgb)
Inherited from RSA
rgb
The cipher text to be decrypted.
Returns The resulting decryption of the <paramref name="rgb" /> parameter in plain text.
When overridden in a derived class, decrypts the input data using the private key.
public
byte[]
Encrypt​(ReadOnlySpan`1 data,
RSAEncryptionPadding padding)
Inherited from RSA
public
int
Encrypt​(ReadOnlySpan`1 data,
Span`1 destination,
RSAEncryptionPadding padding)
Inherited from RSA
public
byte[]
EncryptValue​(byte[] rgb)
Inherited from RSA
rgb
The plain text to be encrypted.
Returns The resulting encryption of the <paramref name="rgb" /> parameter as cipher text.
When overridden in a derived class, encrypts the input data using the public key.
public
byte[]
ExportRSAPrivateKey​()
Inherited from RSA
Returns A byte array containing the PKCS#1 RSAPrivateKey representation of this key.
Exports the current key in the PKCS#1 RSAPrivateKey format.
public
string
ExportRSAPrivateKeyPem​()
Inherited from RSA
Returns A string containing the PEM-encoded PKCS#1 RSAPrivateKey.
Exports the current key in the PKCS#1 RSAPrivateKey format, PEM encoded.
public
byte[]
ExportRSAPublicKey​()
Inherited from RSA
Returns A byte array containing the PKCS#1 RSAPublicKey representation of this key.
Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format.
public
string
ExportRSAPublicKeyPem​()
Inherited from RSA
Returns A string containing the PEM-encoded PKCS#1 RSAPublicKey.
Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format, PEM encoded.
public
void
FromXmlString​(string xmlString)
Inherited from RSA
xmlString
The XML string containing <see cref="T:System.Security.Cryptography.RSA" /> key information.
Initializes an <see cref="T:System.Security.Cryptography.RSA" /> object from the key information from an XML string.
public
int
GetMaxOutputSize​()
Inherited from RSA
Returns The maximum number of bytes an RSA operation can produce.
Gets the maximum number of bytes an RSA operation can produce.
protected
byte[]
HashData​(byte[] data,
int offset,
int count,
HashAlgorithmName hashAlgorithm)
Inherited from RSA
data
The data to be hashed.
offset
The index of the first byte in <paramref name="data" /> that is to be hashed.
count
The number of bytes to hash.
hashAlgorithm
The algorithm to use in hash the data.
Returns The hashed data.
When overridden in a derived class, computes the hash value of a specified portion of a byte array by using a specified hashing algorithm.
protected
byte[]
HashData​(IO.Stream data,
HashAlgorithmName hashAlgorithm)
Inherited from RSA
data
The binary stream to hash.
hashAlgorithm
The hash algorithm.
Returns The hashed data.
When overridden in a derived class, computes the hash value of a specified binary stream by using a specified hashing algorithm.
public
void
ImportFromEncryptedPem​(ReadOnlySpan`1 input,
ReadOnlySpan`1 passwordBytes)
Inherited from RSA
public
void
ImportFromEncryptedPem​(ReadOnlySpan`1 input,
ReadOnlySpan`1 password)
Inherited from RSA
public
void
ImportRSAPrivateKey​(ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from RSA
public
void
ImportRSAPublicKey​(ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from RSA
public
void
ImportSubjectPublicKeyInfo​(ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from RSA
public
byte[]
SignData​(byte[] data,
int offset,
int count,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
data
The input data to hash and sign.
offset
The offset into the array at which to begin using data.
count
The number of bytes in the array to use as data.
hashAlgorithm
The hash algorithm to use to create the hash value.
padding
The padding mode.
Returns The RSA signature for the specified data.
Computes the hash value of a portion of the specified byte array using the specified hash algorithm and padding mode, and signs the resulting hash value.
public
byte[]
SignData​(byte[] data,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
data
The input data to hash and sign.
hashAlgorithm
The hash algorithm to use to create the hash value.
padding
The padding mode.
Returns The RSA signature for the specified data.
Computes the hash value of the specified byte array using the specified hash algorithm and padding mode, and signs the resulting hash value.
public
byte[]
SignData​(IO.Stream data,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
data
The input stream to hash and sign.
hashAlgorithm
The hash algorithm to use to create the hash value.
padding
The padding mode.
Returns The RSA signature for the specified data.
Computes the hash value of the specified stream using the specified hash algorithm and padding mode, and signs the resulting hash value.
public
byte[]
SignData​(ReadOnlySpan`1 data,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
public
int
SignData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
public
byte[]
SignHash​(ReadOnlySpan`1 hash,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
public
int
SignHash​(ReadOnlySpan`1 hash,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
public
string
ToXmlString​(bool includePrivateParameters)
Inherited from RSA
includePrivateParameters
<see langword="true" /> to include a public and private RSA key; <see langword="false" /> to include only the public key.
Returns An XML string containing the key of the current <see cref="T:System.Security.Cryptography.RSA" /> object.
Creates and returns an XML string containing the key of the current <see cref="T:System.Security.Cryptography.RSA" /> object.
public
bool
TryExportRSAPrivateKey​(Span`1 destination,
Int32& bytesWritten)
Inherited from RSA
public
bool
TryExportRSAPrivateKeyPem​(Span`1 destination,
Int32& charsWritten)
Inherited from RSA
public
bool
TryExportRSAPublicKey​(Span`1 destination,
Int32& bytesWritten)
Inherited from RSA
public
bool
TryExportRSAPublicKeyPem​(Span`1 destination,
Int32& charsWritten)
Inherited from RSA
public
bool
TryExportSubjectPublicKeyInfo​(Span`1 destination,
Int32& bytesWritten)
Inherited from RSA
protected
bool
TryHashData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
Int32& bytesWritten)
Inherited from RSA
public
bool
TrySignData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding,
Int32& bytesWritten)
Inherited from RSA
public
bool
VerifyData​(byte[] data,
byte[] signature,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
data
The signed data.
signature
The signature data to be verified.
hashAlgorithm
The hash algorithm used to create the hash value of the data.
padding
The padding mode.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid by calculating the hash value of the specified data using the specified hash algorithm and padding, and comparing it to the provided signature.
public
bool
VerifyData​(byte[] data,
int offset,
int count,
byte[] signature,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
data
The signed data.
offset
The starting index at which to compute the hash.
count
The number of bytes to hash.
signature
The signature data to be verified.
hashAlgorithm
The hash algorithm used to create the hash value of the data.
padding
The padding mode.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid by calculating the hash value of the data in a portion of a byte array using the specified hash algorithm and padding, and comparing it to the provided signature.
public
bool
VerifyData​(IO.Stream data,
byte[] signature,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
data
The signed data.
signature
The signature data to be verified.
hashAlgorithm
The hash algorithm used to create the hash value of the data.
padding
The padding mode.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid by calculating the hash value of the specified stream using the specified hash algorithm and padding, and comparing it to the provided signature.
public
bool
VerifyData​(ReadOnlySpan`1 data,
ReadOnlySpan`1 signature,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding)
Inherited from RSA
Releases all resources used by the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
Releases all resources used by the current instance of the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
public
string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
public
string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 password,
PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
public
byte[]
ExportPkcs8PrivateKey​()
Inherited from AsymmetricAlgorithm
Returns A byte array containing the PKCS#8 PrivateKeyInfo representation of this key.
Exports the current key in the PKCS#8 PrivateKeyInfo format.
public
string
ExportPkcs8PrivateKeyPem​()
Inherited from AsymmetricAlgorithm
Returns A string containing the PEM-encoded PKCS#8 PrivateKeyInfo.
Exports the current key in the PKCS#8 PrivateKeyInfo format, PEM encoded.
public
byte[]
ExportSubjectPublicKeyInfo​()
Inherited from AsymmetricAlgorithm
Returns A byte array containing the X.509 SubjectPublicKeyInfo representation of the public-key portion of this key.
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.
public
string
ExportSubjectPublicKeyInfoPem​()
Inherited from AsymmetricAlgorithm
Returns A string containing the PEM-encoded X.509 SubjectPublicKeyInfo.
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format, PEM encoded.
public
bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters,
Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 password,
PbeParameters pbeParameters,
Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
TryExportPkcs8PrivateKeyPem​(Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
TryExportSubjectPublicKeyInfoPem​(Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object