Repository navigation
OnixLabs.Security.Cryptography.RsaPrivateKey
Represents an RSA cryptographic private key. Supports digital signature creation in both PKCS #1 v1.5 and PSS padding modes, and provides full key import and export in raw, PKCS #8, and PEM formats.
| Namespace | OnixLabs.Security.Cryptography |
| Assembly | OnixLabs.Security.Cryptography.dll (NuGet) |
| Inheritance |
object → PrivateKey → RsaPrivateKey
|
| Implements |
IRsaPrivateKey, ISpanParsable<RsaPrivateKey>, IPrivateKeyDerivable<RsaPublicKey>, IPrivateKeyImportable<RsaPrivateKey>, IPrivateKeyExportable, ICryptoPrimitive<PrivateKey>, IValueEquatable<PrivateKey>, IEquatable<PrivateKey>, IBinaryConvertible, IDisposable
|
public sealed partial class RsaPrivateKey : PrivateKey, IRsaPrivateKey, ISpanParsable<RsaPrivateKey>RsaPrivateKey is the concrete RSA implementation of PrivateKey. It stores raw RSA private key material (PKCS #1 DER) inside the inherited in-memory ProtectedData wrapper, so the key bytes are encrypted at rest and are only transiently decrypted when an operation requires them. Always dispose instances (or use a using statement) to zero the key material promptly.
Signing — use the SignData overloads to hash and sign arbitrary data, or SignHash to sign a pre-computed hash. All signing methods require both a HashAlgorithmName and an RSASignaturePadding:
-
RSASignaturePadding.Pkcs1— deterministic PKCS #1 v1.5 padding, broadly compatible. -
RSASignaturePadding.Pss— probabilistic PSS padding, recommended for new applications.
Obtaining an instance — generate a fresh key pair with Create() or Create(RSAParameters); import existing material via Import, ImportPkcs8, or ImportPem; or parse a hex-encoded key string with Parse / TryParse.
Deriving the public key — call GetPublicKey() to obtain the corresponding RsaPublicKey.
Export formats — the key can be exported as:
| Method | Format |
|---|---|
Export() |
Raw RSA private key bytes (PKCS #1 DER) |
ExportPem() |
Algorithm-native RFC 7468 PEM (RSA PRIVATE KEY) |
ExportPkcs8() |
PKCS #8 DER (unencrypted or password-encrypted) |
ExportPkcs8Pem() |
PKCS #8 RFC 7468 PEM (PRIVATE KEY / ENCRYPTED PRIVATE KEY) |
ToString() returns the raw key bytes encoded as uppercase hexadecimal (Base16). Call ToNamedPrivateKey() to obtain a NamedPrivateKey tagged with the algorithm name "RSA".
Note
RsaPrivateKeyinherits value semantics fromPrivateKey: equality and hash codes are based on the runtime type and key bytes, not reference identity.
using System.Security.Cryptography;
using OnixLabs.Security.Cryptography;
// Generate a new RSA private key (default key size).
using RsaPrivateKey privateKey = RsaPrivateKey.Create();
// Derive the corresponding public key.
RsaPublicKey publicKey = privateKey.GetPublicKey();
byte[] data = System.Text.Encoding.UTF8.GetBytes("Hello, ONIXLabs!");
// Sign data using SHA-256 with PSS padding.
byte[] signature = privateKey.SignData(
data,
HashAlgorithmName.SHA256,
RSASignaturePadding.Pss);
// Verify the signature.
bool valid = publicKey.IsDataValid(
signature,
data,
HashAlgorithmName.SHA256,
RSASignaturePadding.Pss);
Console.WriteLine(valid); // Trueusing System.Security.Cryptography;
using OnixLabs.Security.Cryptography;
using RsaPrivateKey original = RsaPrivateKey.Create();
// Export as PKCS #8 DER.
byte[] pkcs8 = original.ExportPkcs8();
// Re-import from PKCS #8.
using RsaPrivateKey restored = RsaPrivateKey.ImportPkcs8(pkcs8);
Console.WriteLine(original == restored); // True
// Export as PKCS #8 PEM.
string pem = original.ExportPkcs8Pem();
Console.WriteLine(pem); // -----BEGIN PRIVATE KEY----- ...using OnixLabs.Security.Cryptography;
using RsaPrivateKey privateKey = RsaPrivateKey.Create();
NamedPrivateKey named = privateKey.ToNamedPrivateKey();
Console.WriteLine(named.AlgorithmName); // RSA
Console.WriteLine(named); // RSA:<hex-encoded key bytes>| Constructor | Description |
|---|---|
RsaPrivateKey(ReadOnlySpan<byte>) |
Initializes a new instance from a span of bytes. |
RsaPrivateKey(ReadOnlyMemory<byte>) |
Initializes a new instance from a memory region. |
RsaPrivateKey(ReadOnlySequence<byte>) |
Initializes a new instance from a byte sequence. |
public RsaPrivateKey(ReadOnlySpan<byte> keyData)Initializes a new instance of the RsaPrivateKey class. The provided span is copied into an internal ProtectedData wrapper; the span itself is not retained.
| Parameter | Type | Description |
|---|---|---|
keyData |
ReadOnlySpan<byte> |
The underlying key data of the RSA cryptographic private key. |
public RsaPrivateKey(ReadOnlyMemory<byte> keyData)Initializes a new instance of the RsaPrivateKey class. The provided memory region is copied into an internal ProtectedData wrapper; the original memory is not retained.
| Parameter | Type | Description |
|---|---|---|
keyData |
ReadOnlyMemory<byte> |
The underlying key data of the RSA cryptographic private key. |
public RsaPrivateKey(ReadOnlySequence<byte> keyData)Initializes a new instance of the RsaPrivateKey class. The provided byte sequence is copied into an internal ProtectedData wrapper; the original sequence is not retained.
| Parameter | Type | Description |
|---|---|---|
keyData |
ReadOnlySequence<byte> |
The underlying key data of the RSA cryptographic private key. |
| Method | Returns | Description |
|---|---|---|
Create() |
RsaPrivateKey |
Generates a new RSA private key using the default key size. |
Create(RSAParameters) |
RsaPrivateKey |
Creates a new RSA private key from the specified RSAParameters. |
Import(ReadOnlySpan<byte>) |
RsaPrivateKey |
Imports a raw RSA private key from a span of bytes. |
Import(ReadOnlySpan<byte>, out int) |
RsaPrivateKey |
Imports a raw RSA private key from a span of bytes; reports bytes read. |
Import(IBinaryConvertible) |
RsaPrivateKey |
Imports a raw RSA private key from an IBinaryConvertible. |
Import(IBinaryConvertible, out int) |
RsaPrivateKey |
Imports a raw RSA private key from an IBinaryConvertible; reports bytes read. |
ImportPkcs8(ReadOnlySpan<byte>) |
RsaPrivateKey |
Imports an unencrypted PKCS #8 private key from a span. |
ImportPkcs8(ReadOnlySpan<byte>, out int) |
RsaPrivateKey |
Imports an unencrypted PKCS #8 private key from a span; reports bytes read. |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<char>) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from a span using a char password. |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<char>, out int) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from a span using a char password; reports bytes read. |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<byte>) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from a span using a byte password. |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<byte>, out int) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from a span using a byte password; reports bytes read. |
ImportPkcs8(IBinaryConvertible) |
RsaPrivateKey |
Imports an unencrypted PKCS #8 private key from an IBinaryConvertible. |
ImportPkcs8(IBinaryConvertible, out int) |
RsaPrivateKey |
Imports an unencrypted PKCS #8 private key from an IBinaryConvertible; reports bytes read. |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<char>) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from an IBinaryConvertible using a char password. |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<char>, out int) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from an IBinaryConvertible using a char password; reports bytes read. |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<byte>) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from an IBinaryConvertible using a byte password. |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<byte>, out int) |
RsaPrivateKey |
Imports an encrypted PKCS #8 private key from an IBinaryConvertible using a byte password; reports bytes read. |
ImportPem(ReadOnlySpan<char>) |
RsaPrivateKey |
Imports a private key from unencrypted RFC 7468 PEM-encoded text. |
ImportPem(ReadOnlySpan<char>, ReadOnlySpan<char>) |
RsaPrivateKey |
Imports a private key from encrypted PEM using a char password. |
ImportPem(ReadOnlySpan<char>, ReadOnlySpan<byte>) |
RsaPrivateKey |
Imports a private key from encrypted PEM using a byte password. |
Parse(string, IFormatProvider?) |
RsaPrivateKey |
Parses a hex-encoded key string into an RsaPrivateKey. |
Parse(ReadOnlySpan<char>, IFormatProvider?) |
RsaPrivateKey |
Parses a hex-encoded key span into an RsaPrivateKey. |
TryParse(string?, IFormatProvider?, out RsaPrivateKey) |
bool |
Attempts to parse a hex-encoded key string into an RsaPrivateKey. |
TryParse(ReadOnlySpan<char>, IFormatProvider?, out RsaPrivateKey) |
bool |
Attempts to parse a hex-encoded key span into an RsaPrivateKey. |
public static RsaPrivateKey Create()Creates a new RSA cryptographic private key using the platform default key size. The returned key is ready to use for signing and key derivation.
Returns — A new RsaPrivateKey instance.
public static RsaPrivateKey Create(RSAParameters parameters)Creates a new RSA cryptographic private key from the supplied RSAParameters. Use this overload when key material has been obtained from an external source (for example, a hardware token or a key store) and must be wrapped in an RsaPrivateKey.
| Parameter | Type | Description |
|---|---|---|
parameters |
RSAParameters |
The RSA parameters from which to create the key. Must contain the private-key fields (D, DP, DQ, InverseQ, P, Q). |
Returns — A new RsaPrivateKey instance.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
parameters does not represent a valid RSA private key. |
public static RsaPrivateKey Import(ReadOnlySpan<byte> data)
public static RsaPrivateKey Import(ReadOnlySpan<byte> data, out int bytesRead)
public static RsaPrivateKey Import(IBinaryConvertible data)
public static RsaPrivateKey Import(IBinaryConvertible data, out int bytesRead)Imports an RSA private key from its raw PKCS #1 DER-encoded binary representation.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> or IBinaryConvertible
|
The raw RSA private key data to import. |
bytesRead |
out int |
(bytesRead overloads) Receives the number of bytes consumed from data. |
Returns — A new RsaPrivateKey instance containing the imported key.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data does not contain a valid RSA private key. |
public static RsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data)
public static RsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, out int bytesRead)
public static RsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<char> password)
public static RsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<char> password, out int bytesRead)
public static RsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<byte> password)
public static RsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<byte> password, out int bytesRead)
public static RsaPrivateKey ImportPkcs8(IBinaryConvertible data)
public static RsaPrivateKey ImportPkcs8(IBinaryConvertible data, out int bytesRead)
public static RsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<char> password)
public static RsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<char> password, out int bytesRead)
public static RsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<byte> password)
public static RsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<byte> password, out int bytesRead)Imports an RSA private key from PKCS #8 DER-encoded data. Overloads without a password parameter import unencrypted PRIVATE KEY structures; overloads with a password import ENCRYPTED PRIVATE KEY structures.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> or IBinaryConvertible
|
The PKCS #8 DER-encoded key data to import. |
password |
ReadOnlySpan<char> or ReadOnlySpan<byte>
|
(encrypted overloads) The password required to decrypt the key. |
bytesRead |
out int |
(bytesRead overloads) Receives the number of bytes consumed from data. |
Returns — A new RsaPrivateKey instance containing the imported key.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data is not a valid PKCS #8 structure, or decryption failed (wrong password or corrupted data). |
public static RsaPrivateKey ImportPem(ReadOnlySpan<char> data)
public static RsaPrivateKey ImportPem(ReadOnlySpan<char> data, ReadOnlySpan<char> password)
public static RsaPrivateKey ImportPem(ReadOnlySpan<char> data, ReadOnlySpan<byte> password)Imports an RSA private key from RFC 7468 PEM-encoded text. The PEM label determines the encoding: RSA PRIVATE KEY (PKCS #1), PRIVATE KEY (PKCS #8), or ENCRYPTED PRIVATE KEY (encrypted PKCS #8). The two-argument overloads additionally decrypt ENCRYPTED PRIVATE KEY blocks.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<char> |
The PEM-encoded private key data to import. |
password |
ReadOnlySpan<char> or ReadOnlySpan<byte>
|
(encrypted overloads) The password required to decrypt the key. |
Returns — A new RsaPrivateKey instance containing the imported key.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The PEM data is malformed, the label is unsupported, or decryption failed. |
public static RsaPrivateKey Parse(string value, IFormatProvider? provider = null)Parses a string containing the hex-encoded (Base16) raw key bytes into a new RsaPrivateKey instance. If provider is null, Base16FormatProvider.Invariant is used.
| Parameter | Type | Description |
|---|---|---|
value |
string |
The hex-encoded string representing the RSA private key. |
provider |
IFormatProvider? |
The format provider that determines how value is decoded. |
Returns — A new RsaPrivateKey decoded from value.
Exceptions
| Exception | Condition |
|---|---|
FormatException |
value is not a valid encoded key string for the given provider. |
public static RsaPrivateKey Parse(ReadOnlySpan<char> value, IFormatProvider? provider = null)Parses a span containing the hex-encoded (Base16) raw key bytes into a new RsaPrivateKey instance. If provider is null, Base16FormatProvider.Invariant is used.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlySpan<char> |
The hex-encoded character span representing the RSA private key. |
provider |
IFormatProvider? |
The format provider that determines how value is decoded. |
Returns — A new RsaPrivateKey decoded from value.
Exceptions
| Exception | Condition |
|---|---|
FormatException |
value is not a valid encoded key span for the given provider. |
public static bool TryParse(string? value, IFormatProvider? provider, out RsaPrivateKey result)Attempts to parse a string containing the hex-encoded (Base16) raw key bytes into a new RsaPrivateKey instance. Does not throw on failure.
| Parameter | Type | Description |
|---|---|---|
value |
string? |
The hex-encoded string representing the RSA private key, or null. |
provider |
IFormatProvider? |
The format provider that determines how value is decoded. |
result |
out RsaPrivateKey |
When the method returns, contains the parsed RsaPrivateKey, or a default-initialized instance if parsing failed. |
Returns — true if value was successfully parsed; otherwise, false.
public static bool TryParse(ReadOnlySpan<char> value, IFormatProvider? provider, out RsaPrivateKey result)Attempts to parse a span containing the hex-encoded (Base16) raw key bytes into a new RsaPrivateKey instance. Does not throw on failure.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlySpan<char> |
The hex-encoded character span representing the RSA private key. |
provider |
IFormatProvider? |
The format provider that determines how value is decoded. |
result |
out RsaPrivateKey |
When the method returns, contains the parsed RsaPrivateKey, or a default-initialized instance if parsing failed. |
Returns — true if value was successfully parsed; otherwise, false.
| Method | Returns | Description |
|---|---|---|
Export() |
byte[] |
Exports the RSA private key as raw PKCS #1 DER bytes. |
ExportPem() |
string |
Exports the RSA private key as an RSA PRIVATE KEY PEM string. |
ExportPkcs8() |
byte[] |
Exports the RSA private key in PKCS #8 DER format. |
ExportPkcs8(ReadOnlySpan<char>, PbeParameters) |
byte[] |
Exports the RSA private key in encrypted PKCS #8 DER format (char password). |
ExportPkcs8(ReadOnlySpan<byte>, PbeParameters) |
byte[] |
Exports the RSA private key in encrypted PKCS #8 DER format (byte password). |
ExportPkcs8Pem() |
string |
Exports the RSA private key in PKCS #8 RFC 7468 PEM format. |
ExportPkcs8Pem(ReadOnlySpan<char>, PbeParameters) |
string |
Exports the RSA private key in encrypted PKCS #8 PEM format (char password). |
ExportPkcs8Pem(ReadOnlySpan<byte>, PbeParameters) |
string |
Exports the RSA private key in encrypted PKCS #8 PEM format (byte password). |
GetPublicKey() |
RsaPublicKey |
Derives the corresponding RSA public key from this private key. |
SignData(ReadOnlySpan<byte>, HashAlgorithmName, RSASignaturePadding) |
byte[] |
Hashes and signs a span of bytes. |
SignData(ReadOnlySpan<byte>, int, int, HashAlgorithmName, RSASignaturePadding) |
byte[] |
Hashes and signs a byte-range slice. |
SignData(Stream, HashAlgorithmName, RSASignaturePadding) |
byte[] |
Hashes and signs a Stream. |
SignData(IBinaryConvertible, HashAlgorithmName, RSASignaturePadding) |
byte[] |
Hashes and signs an IBinaryConvertible. |
SignHash(Hash, HashAlgorithmName, RSASignaturePadding) |
byte[] |
Signs a pre-computed Hash. |
SignHash(ReadOnlySpan<byte>, HashAlgorithmName, RSASignaturePadding) |
byte[] |
Signs a pre-computed hash supplied as a raw span. |
ToNamedPrivateKey() |
NamedPrivateKey |
Creates a NamedPrivateKey tagging this key with the algorithm name "RSA". |
Inherited members that are unchanged — AsReadOnlyMemory(), AsReadOnlySpan(), Dispose(), Dispose(bool), Equals(PrivateKey?), Equals(object?), GetHashCode(), ToString(), ToString(IFormatProvider), and the == / != operators — are documented on the PrivateKey page.
public byte[] Export()Exports the RSA private key as raw PKCS #1 DER-encoded bytes (equivalent to RSA.ExportRSAPrivateKey()). Use this format when interoperating with systems that expect the traditional RSA PRIVATE KEY DER structure.
Returns — A byte[] containing the raw RSA private key in PKCS #1 DER format.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The key material could not be exported. |
public string ExportPem()Exports the RSA private key as an algorithm-native RFC 7468 PEM string with the RSA PRIVATE KEY label (PKCS #1).
Returns — A string containing the PEM-encoded RSA private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The key material could not be exported. |
public byte[] ExportPkcs8()
public byte[] ExportPkcs8(ReadOnlySpan<char> password, PbeParameters parameters)
public byte[] ExportPkcs8(ReadOnlySpan<byte> password, PbeParameters parameters)Exports the RSA private key in PKCS #8 DER format. The no-argument overload produces an unencrypted PRIVATE KEY structure; the two-argument overloads produce a password-encrypted ENCRYPTED PRIVATE KEY structure according to the supplied PbeParameters.
| Parameter | Type | Description |
|---|---|---|
password |
ReadOnlySpan<char> or ReadOnlySpan<byte>
|
(encrypted overloads) The password used to encrypt the exported key. |
parameters |
PbeParameters |
(encrypted overloads) The password-based encryption parameters (cipher and iteration count). |
Returns — A byte[] containing the RSA private key in PKCS #8 (or encrypted PKCS #8) DER format.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The key material could not be exported. |
public string ExportPkcs8Pem()
public string ExportPkcs8Pem(ReadOnlySpan<char> password, PbeParameters parameters)
public string ExportPkcs8Pem(ReadOnlySpan<byte> password, PbeParameters parameters)Exports the RSA private key as a PKCS #8 RFC 7468 PEM string. The no-argument overload uses the PRIVATE KEY label; the two-argument overloads produce ENCRYPTED PRIVATE KEY PEM.
| Parameter | Type | Description |
|---|---|---|
password |
ReadOnlySpan<char> or ReadOnlySpan<byte>
|
(encrypted overloads) The password used to encrypt the exported key. |
parameters |
PbeParameters |
(encrypted overloads) The password-based encryption parameters. |
Returns — A string containing the PEM-encoded PKCS #8 RSA private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The key material could not be exported. |
public RsaPublicKey GetPublicKey()Derives the RSA public key component from this private key by exporting the PKCS #1 public key and wrapping it in an RsaPublicKey instance.
Returns — The corresponding RsaPublicKey.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The public key component could not be derived. |
public byte[] SignData(ReadOnlySpan<byte> data, HashAlgorithmName algorithm, RSASignaturePadding padding)
public byte[] SignData(ReadOnlySpan<byte> data, int offset, int count, HashAlgorithmName algorithm, RSASignaturePadding padding)
public byte[] SignData(Stream data, HashAlgorithmName algorithm, RSASignaturePadding padding)
public byte[] SignData(IBinaryConvertible data, HashAlgorithmName algorithm, RSASignaturePadding padding)Hashes the specified input data and signs the resulting hash.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> / Stream / IBinaryConvertible
|
The input data to hash and sign. |
offset |
int |
(slice overload) The offset into the span from which to begin reading. |
count |
int |
(slice overload) The number of bytes to read from the span. |
algorithm |
HashAlgorithmName |
The hash algorithm used to hash the input data before signing (e.g. HashAlgorithmName.SHA256). |
padding |
RSASignaturePadding |
The RSA signature padding mode (e.g. RSASignaturePadding.Pkcs1 or RSASignaturePadding.Pss). |
Returns — A byte[] containing the RSA digital signature.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The signing operation failed. |
public byte[] SignHash(Hash hash, HashAlgorithmName algorithm, RSASignaturePadding padding)
public byte[] SignHash(ReadOnlySpan<byte> hash, HashAlgorithmName algorithm, RSASignaturePadding padding)Signs a pre-computed hash value. Use these overloads when the hash has already been computed to avoid double-hashing.
| Parameter | Type | Description |
|---|---|---|
hash |
Hash or ReadOnlySpan<byte>
|
The pre-computed hash to sign. |
algorithm |
HashAlgorithmName |
The hash algorithm that was used to produce hash. |
padding |
RSASignaturePadding |
The RSA signature padding mode. |
Returns — A byte[] containing the RSA digital signature.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current RsaPrivateKey has been disposed. |
CryptographicException |
The signing operation failed. |
public override NamedPrivateKey ToNamedPrivateKey()Creates a new NamedPrivateKey that pairs this RsaPrivateKey with the algorithm name "RSA".
Returns — A NamedPrivateKey with AlgorithmName equal to "RSA" and PrivateKey equal to this instance.
| Operator | Description |
|---|---|
implicit operator RsaPrivateKey(ReadOnlySpan<byte>) |
Implicitly converts a ReadOnlySpan<byte> to an RsaPrivateKey. |
implicit operator RsaPrivateKey(ReadOnlyMemory<byte>) |
Implicitly converts a ReadOnlyMemory<byte> to an RsaPrivateKey. |
implicit operator RsaPrivateKey(ReadOnlySequence<byte>) |
Implicitly converts a ReadOnlySequence<byte> to an RsaPrivateKey. |
public static implicit operator RsaPrivateKey(ReadOnlySpan<byte> value)Creates a new RsaPrivateKey instance from the specified ReadOnlySpan<byte> value. Equivalent to calling the RsaPrivateKey(ReadOnlySpan<byte>) constructor.
public static implicit operator RsaPrivateKey(ReadOnlyMemory<byte> value)Creates a new RsaPrivateKey instance from the specified ReadOnlyMemory<byte> value. Equivalent to calling the RsaPrivateKey(ReadOnlyMemory<byte>) constructor.
public static implicit operator RsaPrivateKey(ReadOnlySequence<byte> value)Creates a new RsaPrivateKey instance from the specified ReadOnlySequence<byte> value. Equivalent to calling the RsaPrivateKey(ReadOnlySequence<byte>) constructor.
ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions