Class CpRSA
Implements
Inherited Members
Namespace: CryptoPro.Security.Cryptography
Assembly: CryptoPro.Security.Cryptography.dll
Syntax
public abstract class CpRSA : AsymmetricAlgorithm, IDisposable
Properties
KeyExchangeAlgorithm
When overridden in a derived class, gets the name of the key exchange algorithm. Otherwise, throws an NotImplementedException.
Declaration
public override string KeyExchangeAlgorithm { get; }
Property Value
| Type | Description |
|---|---|
| string | The name of the key exchange algorithm. |
Overrides
SignatureAlgorithm
When implemented in a derived class, gets the name of the signature algorithm. Otherwise, always throws a NotImplementedException.
Declaration
public override string SignatureAlgorithm { get; }
Property Value
| Type | Description |
|---|---|
| string | The name of the signature algorithm. |
Overrides
Methods
Create()
Declaration
public static CpRSA Create()
Returns
| Type | Description |
|---|---|
| CpRSA |
Create(int)
Declaration
public static CpRSA Create(int keySizeInBits)
Parameters
| Type | Name | Description |
|---|---|---|
| int | keySizeInBits |
Returns
| Type | Description |
|---|---|
| CpRSA |
Create(RSAParameters)
Declaration
public static CpRSA Create(RSAParameters parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| RSAParameters | parameters |
Returns
| Type | Description |
|---|---|
| CpRSA |
Decrypt(byte[], RSAEncryptionPadding)
Declaration
public virtual byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| RSAEncryptionPadding | padding |
Returns
| Type | Description |
|---|---|
| byte[] |
Decrypt(ReadOnlySpan<byte>, RSAEncryptionPadding)
Decrypts the input data using the specified padding mode.
Declaration
public byte[] Decrypt(ReadOnlySpan<byte> data, RSAEncryptionPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The data to decrypt. |
| RSAEncryptionPadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| byte[] | The decrypted data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| CryptographicException |
-or- The decryption operation failed. |
| NotImplementedException | This implementation has not implemented one of Decrypt(byte[], RSAEncryptionPadding) or TryDecrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding, out int). |
See Also
Decrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding)
Decrypts the input data using the specified padding mode.
Declaration
public int Decrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The data to decrypt. |
| Span<byte> | destination | The buffer to receive the decrypted data. |
| RSAEncryptionPadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| int | The total number of bytes written to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | The buffer in |
| CryptographicException |
-or- The decryption operation failed. |
| NotImplementedException | This implementation has not implemented one of Decrypt(byte[], RSAEncryptionPadding) or TryDecrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding, out int). |
See Also
Encrypt(byte[], RSAEncryptionPadding)
Declaration
public virtual byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| RSAEncryptionPadding | padding |
Returns
| Type | Description |
|---|---|
| byte[] |
Encrypt(ReadOnlySpan<byte>, RSAEncryptionPadding)
Encrypts the input data using the specified padding mode.
Declaration
public byte[] Encrypt(ReadOnlySpan<byte> data, RSAEncryptionPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The data to encrypt. |
| RSAEncryptionPadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| byte[] | The encrypted data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| CryptographicException |
-or- The length of data is too long for the combination of KeySize and the selected padding. -or- The encryption operation failed. |
| NotImplementedException | This implementation has not implemented one of Encrypt(byte[], RSAEncryptionPadding) or TryEncrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding, out int). |
See Also
Encrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding)
Encrypts the input data using the specified padding mode.
Declaration
public int Encrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The data to encrypt. |
| Span<byte> | destination | The buffer to receive the encrypted data. |
| RSAEncryptionPadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| int | The total number of bytes written to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | The buffer in |
| CryptographicException |
-or- The length of data is too long for the combination of KeySize and the selected padding. -or- The encryption operation failed. |
| NotImplementedException | This implementation has not implemented one of Encrypt(byte[], RSAEncryptionPadding) or TryEncrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding, out int). |
See Also
ExportParameters(bool)
Declaration
public abstract RSAParameters ExportParameters(bool includePrivateParameters)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | includePrivateParameters |
Returns
| Type | Description |
|---|---|
| RSAParameters |
ExportRSAPrivateKey()
Declaration
public virtual byte[] ExportRSAPrivateKey()
Returns
| Type | Description |
|---|---|
| byte[] |
ExportRSAPrivateKeyPem()
Exports the current key in the PKCS#1 RSAPrivateKey format, PEM encoded.
Declaration
public string ExportRSAPrivateKeyPem()
Returns
| Type | Description |
|---|---|
| string | A string containing the PEM-encoded PKCS#1 RSAPrivateKey. |
Remarks
A PEM-encoded PKCS#1 RSAPrivateKey will begin with -----BEGIN RSA
PRIVATE KEY----- and end with -----END RSA PRIVATE
KEY-----, with the base64 encoded DER contents of the key
between the PEM boundaries.
The PEM is encoded according to the IETF RFC 7468 "strict" encoding rules.
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
ExportRSAPublicKey()
Declaration
public virtual byte[] ExportRSAPublicKey()
Returns
| Type | Description |
|---|---|
| byte[] |
ExportRSAPublicKeyPem()
Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format, PEM encoded.
Declaration
public string ExportRSAPublicKeyPem()
Returns
| Type | Description |
|---|---|
| string | A string containing the PEM-encoded PKCS#1 RSAPublicKey. |
Remarks
A PEM-encoded PKCS#1 RSAPublicKey will begin with -----BEGIN RSA
PUBLIC KEY----- and end with -----END RSA PUBLIC
KEY-----, with the base64 encoded DER contents of the key
between the PEM boundaries.
The PEM is encoded according to the IETF RFC 7468 "strict" encoding rules.
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
GetMaxOutputSize()
Gets the maximum number of bytes an RSA operation can produce.
Declaration
public int GetMaxOutputSize()
Returns
| Type | Description |
|---|---|
| int | The maximum number of bytes an RSA operation can produce. |
Remarks
The maximum output size is defined by the RSA modulus, or key size. The key size, in bytes, is the maximum output size. If the key size is not an even number of bytes, then it is rounded up to the nearest number of whole bytes for purposes of determining the maximum output size.
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | KeySize returned a value that is not a possible RSA key size. |
HashData(byte[], int, int, CpHashAlgorithmName)
Declaration
protected virtual byte[] HashData(byte[] data, int offset, int count, CpHashAlgorithmName hashAlgorithm)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| int | offset | |
| int | count | |
| CpHashAlgorithmName | hashAlgorithm |
Returns
| Type | Description |
|---|---|
| byte[] |
HashData(Stream, CpHashAlgorithmName)
Declaration
protected virtual byte[] HashData(Stream data, CpHashAlgorithmName hashAlgorithm)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | data | |
| CpHashAlgorithmName | hashAlgorithm |
Returns
| Type | Description |
|---|---|
| byte[] |
ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte>, ReadOnlySpan<byte>, out int)
When overridden in a derived class, imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.
Declaration
public override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source, out int bytesRead)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | passwordBytes | The bytes to use as a password when decrypting the key material. |
| ReadOnlySpan<byte> | source | The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding. |
| int | bytesRead | When this method returns, contains a value that indicates the number of bytes read from |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The password is incorrect. -or- The contents of -or- The contents of -or- The contents of -or- The contents of -or- The algorithm-specific key import failed. |
| NotImplementedException | A derived type has not overriden this member. |
ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char>, ReadOnlySpan<byte>, out int)
When overridden in a derived class, imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.
Declaration
public override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> source, out int bytesRead)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | password | The password to use for decrypting the key material. |
| ReadOnlySpan<byte> | source | The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding. |
| int | bytesRead | When this method returns, contains a value that indicates the number of bytes read from |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The password is incorrect. -or- The contents of -or- The contents of -or- The contents of -or- The algorithm-specific key import failed. |
| NotImplementedException | A derived type has not overriden this member. |
ImportFromEncryptedPem(ReadOnlySpan<char>, ReadOnlySpan<byte>)
Imports an encrypted RFC 7468 PEM-encoded private key, replacing the keys for this object.
Declaration
public override void ImportFromEncryptedPem(ReadOnlySpan<char> input, ReadOnlySpan<byte> passwordBytes)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | input | The PEM text of the encrypted key to import. |
| ReadOnlySpan<byte> | passwordBytes | The bytes to use as a password when decrypting the key material. |
Overrides
Remarks
The password bytes are passed directly into the Key Derivation
Function (KDF) used by the algorithm indicated by
pbeParameters. This enables compatibility with other systems
which use a text encoding other than UTF-8 when processing passwords
with PBKDF2 (Password-Based Key Derivation Function 2).
Unsupported or malformed PEM-encoded objects will be ignored. If multiple supported PEM labels are found, an exception is thrown to prevent importing a key when the key is ambiguous.
This method supports the ENCRYPTED PRIVATE KEY PEM label.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
-or-
|
| CryptographicException | The password is incorrect. -or-
The base-64 decoded contents of the PEM text from
-or-
The base-64 decoded contents of the PEM text from
-or-
The base-64 decoded contents of the PEM text from
-or- The algorithm-specific key import failed. |
ImportFromEncryptedPem(ReadOnlySpan<char>, ReadOnlySpan<char>)
Imports an encrypted RFC 7468 PEM-encoded private key, replacing the keys for this object.
Declaration
public override void ImportFromEncryptedPem(ReadOnlySpan<char> input, ReadOnlySpan<char> password)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | input | The PEM text of the encrypted key to import. |
| ReadOnlySpan<char> | password | The password to use for decrypting the key material. |
Overrides
Remarks
When the base-64 decoded contents of input
indicate an algorithm that uses PBKDF1 (Password-Based Key
Derivation Function 1) or PBKDF2 (Password-Based Key Derivation
Function 2), the password is converted to bytes via the UTF-8
encoding.
Unsupported or malformed PEM-encoded objects will be ignored. If multiple supported PEM labels are found, an exception is thrown to prevent importing a key when the key is ambiguous.
This method supports the ENCRYPTED PRIVATE KEY PEM label.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
-or-
|
| CryptographicException | The password is incorrect. -or-
The base-64 decoded contents of the PEM text from
-or-
The base-64 decoded contents of the PEM text from
-or-
The base-64 decoded contents of the PEM text from
-or- The algorithm-specific key import failed. |
ImportFromPem(ReadOnlySpan<char>)
Imports an RFC 7468 PEM-encoded key, replacing the keys for this object.
Declaration
public override void ImportFromPem(ReadOnlySpan<char> input)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | input | The PEM text of the key to import. |
Overrides
Remarks
Unsupported or malformed PEM-encoded objects will be ignored. If multiple supported PEM labels are found, an exception is raised to prevent importing a key when the key is ambiguous.
This method supports the following PEM labels:
- PUBLIC KEY
- PRIVATE KEY
- RSA PRIVATE KEY
- RSA PUBLIC KEY
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
-or-
-or-
|
ImportParameters(RSAParameters)
Declaration
public abstract void ImportParameters(RSAParameters parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| RSAParameters | parameters |
ImportPkcs8PrivateKey(ReadOnlySpan<byte>, out int)
When overriden in a derived class, imports the public/private keypair from a PKCS#8 PrivateKeyInfo structure after decryption, replacing the keys for this object.
Declaration
public override void ImportPkcs8PrivateKey(ReadOnlySpan<byte> source, out int bytesRead)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | source | The bytes of a PKCS#8 PrivateKeyInfo structure in the ASN.1-BER encoding. |
| int | bytesRead | When this method returns, contains a value that indicates the number of bytes read from |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The contents of -or- The contents of -or- The contents of -or- The algorithm-specific key import failed. |
| NotImplementedException | A derived type has not overriden this member. |
ImportRSAPrivateKey(ReadOnlySpan<byte>, out int)
Declaration
public virtual void ImportRSAPrivateKey(ReadOnlySpan<byte> source, out int bytesRead)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | source | |
| int | bytesRead |
ImportRSAPublicKey(ReadOnlySpan<byte>, out int)
Imports RSA public key.
Declaration
public virtual void ImportRSAPublicKey(ReadOnlySpan<byte> source, out int bytesRead)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | source | The encoded public key. |
| int | bytesRead | The number of bytes read from the source. |
ImportSubjectPublicKeyInfo(ReadOnlySpan<byte>, out int)
When overriden in a derived class, imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption, replacing the keys for this object.
Declaration
public override void ImportSubjectPublicKeyInfo(ReadOnlySpan<byte> source, out int bytesRead)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | source | The bytes of an X.509 SubjectPublicKeyInfo structure in the ASN.1-DER encoding. |
| int | bytesRead | When this method returns, contains a value that indicates the number of bytes read from |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The contents of -or- The contents of -or- The contents of -or- The algorithm-specific key import failed. |
| NotImplementedException | A derived type has not overriden this member. |
SignData(byte[], CpHashAlgorithmName, RSASignaturePadding)
Declaration
public byte[] SignData(byte[] data, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| byte[] |
SignData(byte[], int, int, CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual byte[] SignData(byte[] data, int offset, int count, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| int | offset | |
| int | count | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| byte[] |
SignData(Stream, CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual byte[] SignData(Stream data, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | data | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| byte[] |
SignData(ReadOnlySpan<byte>, CpHashAlgorithmName, RSASignaturePadding)
Computes the hash value of the specified data and signs it.
Declaration
public byte[] SignData(ReadOnlySpan<byte> data, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The input data to hash and sign. |
| CpHashAlgorithmName | hashAlgorithm | The hash algorithm to use to create the hash value. |
| RSASignaturePadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| byte[] | The RSA signature for the specified data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| ArgumentException |
|
| CryptographicException |
-or- This instance represents only a public key. -or- An error occurred creating the signature. |
| NotImplementedException | This implementation has not implemented one of TrySignData(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int), TrySignHash(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int), or SignHash(byte[], CpHashAlgorithmName, RSASignaturePadding). |
SignData(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding)
Computes the hash of the provided data with the specified algorithm and sign the hash with the current key, writing the signature into a provided buffer.
Declaration
public int SignData(ReadOnlySpan<byte> data, Span<byte> destination, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The input data to hash and sign. |
| Span<byte> | destination | The buffer to receive the RSA signature. |
| CpHashAlgorithmName | hashAlgorithm | The hash algorithm to use to create the hash value. |
| RSASignaturePadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| int | The total number of bytes written to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| ArgumentException |
-or-
The buffer in |
| CryptographicException |
-or- This instance represents only a public key. -or- An error occurred creating the signature. |
| NotImplementedException | This implementation has not implemented one of TrySignData(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int), TrySignHash(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int), or SignHash(byte[], CpHashAlgorithmName, RSASignaturePadding). |
SignHash(byte[], CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual byte[] SignHash(byte[] hash, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | hash | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| byte[] |
SignHash(ReadOnlySpan<byte>, CpHashAlgorithmName, RSASignaturePadding)
Computes the signature for the specified hash value using the specified padding.
Declaration
public byte[] SignHash(ReadOnlySpan<byte> hash, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | hash | The hash value of the data to be signed. |
| CpHashAlgorithmName | hashAlgorithm | The hash algorithm used to create the hash of
|
| RSASignaturePadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| byte[] | The RSA signature for the specified hash value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| ArgumentException |
|
| CryptographicException |
-or- This instance represents only a public key. -or- An error occurred creating the signature. |
| NotImplementedException | This implementation has not implemented one of TrySignHash(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int) or SignHash(byte[], CpHashAlgorithmName, RSASignaturePadding). |
SignHash(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding)
Sign the hash with the current key, writing the signature into a provided buffer.
Declaration
public int SignHash(ReadOnlySpan<byte> hash, Span<byte> destination, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | hash | The hash value of the data to be signed. |
| Span<byte> | destination | The buffer to receive the RSA signature. |
| CpHashAlgorithmName | hashAlgorithm | The hash algorithm used to create the hash of
|
| RSASignaturePadding | padding | The padding mode. |
Returns
| Type | Description |
|---|---|
| int | The total number of bytes written to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| ArgumentException |
-or-
The buffer in |
| CryptographicException |
-or- This instance represents only a public key. -or- An error occurred creating the signature. |
| NotImplementedException | This implementation has not implemented one of TrySignHash(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int) or SignHash(byte[], CpHashAlgorithmName, RSASignaturePadding). |
TryDecrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding, out int)
Declaration
public virtual bool TryDecrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | |
| Span<byte> | destination | |
| RSAEncryptionPadding | padding | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TryEncrypt(ReadOnlySpan<byte>, Span<byte>, RSAEncryptionPadding, out int)
Declaration
public virtual bool TryEncrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | |
| Span<byte> | destination | |
| RSAEncryptionPadding | padding | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte>, PbeParameters, Span<byte>, out int)
When overridden in a derived class, attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a byte-based password.
Declaration
public override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | passwordBytes | The bytes to use as a password when encrypting the key material. |
| PbeParameters | pbeParameters | The password-based encryption (PBE) parameters to use when encrypting the key material. |
| Span<byte> | destination | The byte span to receive the PKCS#8 EncryptedPrivateKeyInfo data. |
| int | bytesWritten | When this method returns, contains a value that indicates the number of bytes written to |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. -or-
|
| NotImplementedException | A derived type has not overriden this member. |
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char>, PbeParameters, Span<byte>, out int)
When overriden in a derived class, attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.
Declaration
public override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | password | The password to use when encrypting the key material. |
| PbeParameters | pbeParameters | The password-based encryption (PBE) parameters to use when encrypting the key material. |
| Span<byte> | destination | The byte span to receive the PKCS#8 EncryptedPrivateKeyInfo data. |
| int | bytesWritten | When this method returns, contains a value that indicates the number of bytes written to |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
| NotImplementedException | A derived type has not overriden this member. |
TryExportPkcs8PrivateKey(Span<byte>, out int)
When overridden in a derived class, attempts to export the current key in the PKCS#8 PrivateKeyInfo format into a provided buffer.
Declaration
public override bool TryExportPkcs8PrivateKey(Span<byte> destination, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | destination | The byte span to receive the PKCS#8 PrivateKeyInfo data. |
| int | bytesWritten | When this method returns, contains a value that indicates the number of bytes written to |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
| NotImplementedException | A derived type has not overriden this member. |
TryExportRSAPrivateKey(Span<byte>, out int)
Declaration
public virtual bool TryExportRSAPrivateKey(Span<byte> destination, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | destination | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TryExportRSAPrivateKeyPem(Span<char>, out int)
Attempts to export the current key in the PEM-encoded PKCS#1 RSAPrivateKey format into a provided buffer.
Declaration
public bool TryExportRSAPrivateKeyPem(Span<char> destination, out int charsWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<char> | destination | The character span to receive the PEM-encoded PKCS#1 RSAPrivateKey data. |
| int | charsWritten | When this method returns, contains a value that indicates the number
of characters written to |
Returns
| Type | Description |
|---|---|
| bool | true if |
Remarks
A PEM-encoded PKCS#1 RSAPrivateKey will begin with -----BEGIN RSA
PRIVATE KEY----- and end with -----END RSA PRIVATE
KEY-----, with the base64 encoded DER contents of the key
between the PEM boundaries.
The PEM is encoded according to the IETF RFC 7468 "strict" encoding rules.
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
TryExportRSAPublicKey(Span<byte>, out int)
Declaration
public virtual bool TryExportRSAPublicKey(Span<byte> destination, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | destination | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TryExportRSAPublicKeyPem(Span<char>, out int)
Attempts to export the current key in the PEM-encoded PKCS#1 RSAPublicKey format into a provided buffer.
Declaration
public bool TryExportRSAPublicKeyPem(Span<char> destination, out int charsWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<char> | destination | The character span to receive the PEM-encoded PKCS#1 RSAPublicKey data. |
| int | charsWritten | When this method returns, contains a value that indicates the number
of characters written to |
Returns
| Type | Description |
|---|---|
| bool | true if |
Remarks
A PEM-encoded PKCS#1 RSAPublicKey will begin with -----BEGIN RSA
PUBLIC KEY----- and end with -----END RSA PUBLIC
KEY-----, with the base64 encoded DER contents of the key
between the PEM boundaries.
The PEM is encoded according to the IETF RFC 7468 "strict" encoding rules.
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
TryExportSubjectPublicKeyInfo(Span<byte>, out int)
When overridden in a derived class, attempts to export the current key in the X.509 SubjectPublicKeyInfo format into a provided buffer.
Declaration
public override bool TryExportSubjectPublicKeyInfo(Span<byte> destination, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | destination | The byte span to receive the X.509 SubjectPublicKeyInfo data. |
| int | bytesWritten | When this method returns, contains a value that indicates the number of bytes written to |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | The key could not be exported. |
| NotImplementedException | A derived type has not overriden this member. |
TryHashData(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, out int)
Declaration
protected virtual bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, CpHashAlgorithmName hashAlgorithm, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | |
| Span<byte> | destination | |
| CpHashAlgorithmName | hashAlgorithm | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TrySignData(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int)
Declaration
public virtual bool TrySignData(ReadOnlySpan<byte> data, Span<byte> destination, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | |
| Span<byte> | destination | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TrySignHash(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int)
Declaration
public virtual bool TrySignHash(ReadOnlySpan<byte> hash, Span<byte> destination, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | hash | |
| Span<byte> | destination | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
TrySignHashCore(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int)
Declaration
protected abstract bool TrySignHashCore(ReadOnlySpan<byte> hash, Span<byte> destination, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | hash | |
| Span<byte> | destination | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding | |
| int | bytesWritten |
Returns
| Type | Description |
|---|---|
| bool |
VerifyData(byte[], byte[], CpHashAlgorithmName, RSASignaturePadding)
Declaration
public bool VerifyData(byte[] data, byte[] signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| byte[] | signature | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool |
VerifyData(byte[], int, int, byte[], CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| int | offset | |
| int | count | |
| byte[] | signature | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool |
VerifyData(Stream, byte[], CpHashAlgorithmName, RSASignaturePadding)
Declaration
public bool VerifyData(Stream data, byte[] signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | data | |
| byte[] | signature | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool |
VerifyData(ReadOnlySpan<byte>, ReadOnlySpan<byte>, CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual bool VerifyData(ReadOnlySpan<byte> data, ReadOnlySpan<byte> signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | |
| ReadOnlySpan<byte> | signature | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool |
VerifyHash(byte[], byte[], CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual bool VerifyHash(byte[] hash, byte[] signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | hash | |
| byte[] | signature | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool |
VerifyHash(ReadOnlySpan<byte>, ReadOnlySpan<byte>, CpHashAlgorithmName, RSASignaturePadding)
Declaration
public virtual bool VerifyHash(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | hash | |
| ReadOnlySpan<byte> | signature | |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool |
VerifyHashCore(ReadOnlySpan<byte>, ReadOnlySpan<byte>, CpHashAlgorithmName, RSASignaturePadding)
Verifies that a digital signature is valid for the provided hash.
Declaration
protected abstract bool VerifyHashCore(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | hash | The signed hash. |
| ReadOnlySpan<byte> | signature | The signature to verify. |
| CpHashAlgorithmName | hashAlgorithm | |
| RSASignaturePadding | padding |
Returns
| Type | Description |
|---|---|
| bool | true if the digital signature is valid for the provided data; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| CryptographicException | An error occurred in the verification operation. |