Repository navigation
OnixLabs.Security.Cryptography.EddsaPrivateKey
Represents an EdDSA (Edwards-curve Digital Signature Algorithm) cryptographic private key, as specified in RFC 8032 (Ed25519, PureEdDSA).
| Namespace | OnixLabs.Security.Cryptography |
| Assembly | OnixLabs.Security.Cryptography.dll (NuGet) |
| Inheritance |
object → PrivateKey → EddsaPrivateKey
|
| Implements |
IEddsaPrivateKey, ISpanParsable<EddsaPrivateKey>, IPrivateKeyDerivable<EddsaPublicKey>, IPrivateKeyRawImportable<EddsaPrivateKey>, IPrivateKeyPkcs8Importable<EddsaPrivateKey>, IPrivateKeyPemImportable<EddsaPrivateKey>, IPrivateKeyRawExportable, IPrivateKeyPkcs8Exportable, IPrivateKeyPkcs8PemExportable, ICryptoPrimitive<PrivateKey>, IValueEquatable<PrivateKey>, IEquatable<PrivateKey>, IBinaryConvertible, IDisposable
|
public sealed partial class EddsaPrivateKey : PrivateKey, IEddsaPrivateKey, ISpanParsable<EddsaPrivateKey>EddsaPrivateKey wraps a 32-byte Ed25519 seed. The seed is stored in the parent class's ProtectedData wrapper, which encrypts the bytes at rest inside the process. The seed is only decrypted momentarily when signing or deriving the corresponding public key, and is zeroed immediately afterwards using CryptographicOperations.ZeroMemory.
EdDSA (PureEdDSA) is a deterministic signing scheme: given the same private seed and the same message, SignData always produces the same 64-byte signature. There is no per-signature randomness and no hash algorithm parameter — the Ed25519 algorithm internally applies SHA-512 twice as part of the signing protocol. The four SignData overloads accept different data representations (ReadOnlySpan<byte>, a sliced span with offset and count, Stream, or IBinaryConvertible) but all ultimately sign the complete raw message bytes.
Note Because PureEdDSA hashes the message twice internally,
SignDatamust hold the entire message in memory. TheStreamoverload reads the stream to completion before signing.
Key material can be imported and exported in three formats:
-
Raw seed bytes — the bare 32-byte Ed25519 seed (
Import/Export). -
PKCS#8 DER — the standard ASN.1 format (
ImportPkcs8/ExportPkcs8). Password-based encryption (PBE) is supported via the overloads that accept a password andPbeParameters. -
RFC 7468 PEM — Base64-armored PKCS#8 (
ImportPem/ExportPkcs8Pem). The unencrypted label isPRIVATE KEY; the encrypted label isENCRYPTED PRIVATE KEY.
A fresh key can be generated with the static Create() factory, which fills a stack-allocated seed buffer from RandomNumberGenerator, constructs the instance, and then zeros the stack buffer.
The corresponding public key is obtained via GetPublicKey(), which derives the Ed25519 public point from the seed without needing a separate key-pair generation step.
Text parsing (Parse / TryParse) decodes a hex (Base16) string by default; pass an alternative IFormatProvider (for example, a Base58 or Base64 provider) to accept other encodings.
EddsaPrivateKey inherits value semantics, disposal behaviour, ToString, equality operators, and all base PrivateKey methods from PrivateKey. Always dispose instances promptly (or use a using statement) to zero the key material.
using OnixLabs.Security.Cryptography;
// Generate a fresh Ed25519 private key.
using EddsaPrivateKey privateKey = EddsaPrivateKey.Create();
// Derive the corresponding public key.
EddsaPublicKey publicKey = privateKey.GetPublicKey();
byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello, ONIXLabs!");
// Sign the message directly — no hash algorithm is specified; Ed25519 handles hashing internally.
byte[] signature = privateKey.SignData(message);
// Verify the signature.
bool valid = publicKey.IsDataValid(signature, message);
Console.WriteLine(valid); // Trueusing OnixLabs.Security.Cryptography;
using EddsaPrivateKey original = EddsaPrivateKey.Create();
// Export as an unencrypted PKCS#8 PEM string.
string pem = original.ExportPkcs8Pem();
Console.WriteLine(pem);
// -----BEGIN PRIVATE KEY-----
// ...
// -----END PRIVATE KEY-----
// Re-import from PEM.
using EddsaPrivateKey restored = EddsaPrivateKey.ImportPem(pem.AsSpan());
Console.WriteLine(original == restored); // Trueusing System.Security.Cryptography;
using OnixLabs.Security.Cryptography;
using EddsaPrivateKey original = EddsaPrivateKey.Create();
PbeParameters pbeParams = new(PbeEncryptionAlgorithm.Aes256Cbc, HashAlgorithmName.SHA256, 100_000);
string encryptedPem = original.ExportPkcs8Pem("correct horse battery staple".AsSpan(), pbeParams);
using EddsaPrivateKey restored = EddsaPrivateKey.ImportPem(
encryptedPem.AsSpan(),
"correct horse battery staple".AsSpan());
Console.WriteLine(original == restored); // Trueusing OnixLabs.Security.Cryptography;
using EddsaPrivateKey privateKey = EddsaPrivateKey.Create();
NamedPrivateKey named = privateKey.ToNamedPrivateKey();
Console.WriteLine(named.AlgorithmName); // EDDSA
Console.WriteLine(named); // EDDSA:<hex-encoded key bytes>| Constructor | Description |
|---|---|
EddsaPrivateKey(ReadOnlySpan<byte>) |
Initializes a new instance of the EddsaPrivateKey class from a span of bytes. |
EddsaPrivateKey(ReadOnlyMemory<byte>) |
Initializes a new instance of the EddsaPrivateKey class from a memory region. |
EddsaPrivateKey(ReadOnlySequence<byte>) |
Initializes a new instance of the EddsaPrivateKey class from a byte sequence. |
public EddsaPrivateKey(ReadOnlySpan<byte> keyData)Initializes a new instance of the EddsaPrivateKey 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 EdDSA cryptographic private key. |
public EddsaPrivateKey(ReadOnlyMemory<byte> keyData)Initializes a new instance of the EddsaPrivateKey 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 EdDSA cryptographic private key. |
public EddsaPrivateKey(ReadOnlySequence<byte> keyData)Initializes a new instance of the EddsaPrivateKey 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 EdDSA cryptographic private key. |
| Method | Returns | Description |
|---|---|---|
Create() |
EddsaPrivateKey |
Creates a new EddsaPrivateKey from a cryptographically random seed. |
Import(ReadOnlySpan<byte>) |
EddsaPrivateKey |
Imports a raw 32-byte Ed25519 seed. |
Import(ReadOnlySpan<byte>, out int) |
EddsaPrivateKey |
Imports a raw 32-byte Ed25519 seed and reports the number of bytes consumed. |
Import(IBinaryConvertible) |
EddsaPrivateKey |
Imports a raw Ed25519 seed from an IBinaryConvertible. |
Import(IBinaryConvertible, out int) |
EddsaPrivateKey |
Imports a raw Ed25519 seed from an IBinaryConvertible and reports bytes consumed. |
ImportPkcs8(ReadOnlySpan<byte>) |
EddsaPrivateKey |
Imports an unencrypted PKCS#8 DER-encoded Ed25519 private key. |
ImportPkcs8(ReadOnlySpan<byte>, out int) |
EddsaPrivateKey |
Imports an unencrypted PKCS#8 DER-encoded key and reports bytes consumed. |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<char>) |
EddsaPrivateKey |
Decrypts and imports a password-protected PKCS#8 DER-encoded key (char password). |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<char>, out int) |
EddsaPrivateKey |
Decrypts and imports a password-protected PKCS#8 DER-encoded key (char password) and reports bytes consumed. |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<byte>) |
EddsaPrivateKey |
Decrypts and imports a password-protected PKCS#8 DER-encoded key (byte password). |
ImportPkcs8(ReadOnlySpan<byte>, ReadOnlySpan<byte>, out int) |
EddsaPrivateKey |
Decrypts and imports a password-protected PKCS#8 DER-encoded key (byte password) and reports bytes consumed. |
ImportPkcs8(IBinaryConvertible) |
EddsaPrivateKey |
Imports an unencrypted PKCS#8 DER key from an IBinaryConvertible. |
ImportPkcs8(IBinaryConvertible, out int) |
EddsaPrivateKey |
Imports an unencrypted PKCS#8 DER key from an IBinaryConvertible and reports bytes consumed. |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<char>) |
EddsaPrivateKey |
Decrypts and imports a PKCS#8 DER key from an IBinaryConvertible (char password). |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<char>, out int) |
EddsaPrivateKey |
Decrypts and imports a PKCS#8 DER key from an IBinaryConvertible (char password) and reports bytes consumed. |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<byte>) |
EddsaPrivateKey |
Decrypts and imports a PKCS#8 DER key from an IBinaryConvertible (byte password). |
ImportPkcs8(IBinaryConvertible, ReadOnlySpan<byte>, out int) |
EddsaPrivateKey |
Decrypts and imports a PKCS#8 DER key from an IBinaryConvertible (byte password) and reports bytes consumed. |
ImportPem(ReadOnlySpan<char>) |
EddsaPrivateKey |
Imports an unencrypted RFC 7468 PEM-encoded Ed25519 private key. |
ImportPem(ReadOnlySpan<char>, ReadOnlySpan<char>) |
EddsaPrivateKey |
Decrypts and imports a password-protected PEM-encoded Ed25519 private key (char password). |
ImportPem(ReadOnlySpan<char>, ReadOnlySpan<byte>) |
EddsaPrivateKey |
Decrypts and imports a password-protected PEM-encoded Ed25519 private key (byte password). |
Parse(string, IFormatProvider?) |
EddsaPrivateKey |
Parses a string into an EddsaPrivateKey. |
Parse(ReadOnlySpan<char>, IFormatProvider?) |
EddsaPrivateKey |
Parses a character span into an EddsaPrivateKey. |
TryParse(string?, IFormatProvider?, out EddsaPrivateKey) |
bool |
Attempts to parse a string into an EddsaPrivateKey. |
TryParse(ReadOnlySpan<char>, IFormatProvider?, out EddsaPrivateKey) |
bool |
Attempts to parse a character span into an EddsaPrivateKey. |
public static EddsaPrivateKey Create()Creates a new EddsaPrivateKey instance from a cryptographically random seed. The 32-byte seed is generated using RandomNumberGenerator.Fill into a stack-allocated buffer, which is zeroed immediately after the key is constructed.
Returns — A new EddsaPrivateKey instance backed by a randomly generated Ed25519 seed.
public static EddsaPrivateKey Import(ReadOnlySpan<byte> data)Imports an EddsaPrivateKey from the raw 32-byte Ed25519 seed.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The raw Ed25519 seed bytes to import. |
Returns — A new EddsaPrivateKey backed by the supplied seed.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data is not exactly 32 bytes in length. |
public static EddsaPrivateKey Import(ReadOnlySpan<byte> data, out int bytesRead)Imports an EddsaPrivateKey from the raw 32-byte Ed25519 seed and reports the number of bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The raw Ed25519 seed bytes to import. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data (always 32 on success). |
Returns — A new EddsaPrivateKey backed by the supplied seed.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data is not exactly 32 bytes in length. |
public static EddsaPrivateKey Import(IBinaryConvertible data)Imports an EddsaPrivateKey from the raw Ed25519 seed held in an IBinaryConvertible value.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value whose raw bytes are the Ed25519 seed. |
Returns — A new EddsaPrivateKey backed by the supplied seed.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The binary data is not exactly 32 bytes in length. |
public static EddsaPrivateKey Import(IBinaryConvertible data, out int bytesRead)Imports an EddsaPrivateKey from the raw Ed25519 seed held in an IBinaryConvertible value and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value whose raw bytes are the Ed25519 seed. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed (always 32 on success). |
Returns — A new EddsaPrivateKey backed by the supplied seed.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The binary data is not exactly 32 bytes in length. |
public static EddsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data)Imports an EddsaPrivateKey from an unencrypted PKCS#8 DER-encoded Ed25519 private key.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The DER-encoded PKCS#8 private key bytes to import. |
Returns — A new EddsaPrivateKey extracted from the PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data is not a valid unencrypted PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, out int bytesRead)Imports an EddsaPrivateKey from an unencrypted PKCS#8 DER-encoded Ed25519 private key and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The DER-encoded PKCS#8 private key bytes to import. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data. |
Returns — A new EddsaPrivateKey extracted from the PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data is not a valid unencrypted PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<char> password)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key using a character-array password.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The encrypted DER-encoded PKCS#8 private key bytes to import. |
password |
ReadOnlySpan<char> |
The password used to decrypt the key. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<char> password, out int bytesRead)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key (char password) and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The encrypted DER-encoded PKCS#8 private key bytes to import. |
password |
ReadOnlySpan<char> |
The password used to decrypt the key. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<byte> password)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key using a byte-array password.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The encrypted DER-encoded PKCS#8 private key bytes to import. |
password |
ReadOnlySpan<byte> |
The password bytes used to decrypt the key. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(ReadOnlySpan<byte> data, ReadOnlySpan<byte> password, out int bytesRead)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key (byte password) and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The encrypted DER-encoded PKCS#8 private key bytes to import. |
password |
ReadOnlySpan<byte> |
The password bytes used to decrypt the key. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(IBinaryConvertible data)Imports an EddsaPrivateKey from an unencrypted PKCS#8 DER-encoded Ed25519 private key held in an IBinaryConvertible.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value containing the DER-encoded PKCS#8 private key. |
Returns — A new EddsaPrivateKey extracted from the PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The data is not a valid unencrypted PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(IBinaryConvertible data, out int bytesRead)Imports an EddsaPrivateKey from an unencrypted PKCS#8 DER-encoded Ed25519 private key held in an IBinaryConvertible and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value containing the DER-encoded PKCS#8 private key. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data. |
Returns — A new EddsaPrivateKey extracted from the PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The data is not a valid unencrypted PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<char> password)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key held in an IBinaryConvertible (char password).
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value containing the encrypted DER-encoded PKCS#8 private key. |
password |
ReadOnlySpan<char> |
The password used to decrypt the key. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<char> password, out int bytesRead)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key held in an IBinaryConvertible (char password) and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value containing the encrypted DER-encoded PKCS#8 private key. |
password |
ReadOnlySpan<char> |
The password used to decrypt the key. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<byte> password)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key held in an IBinaryConvertible (byte password).
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value containing the encrypted DER-encoded PKCS#8 private key. |
password |
ReadOnlySpan<byte> |
The password bytes used to decrypt the key. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPkcs8(IBinaryConvertible data, ReadOnlySpan<byte> password, out int bytesRead)Decrypts and imports an EddsaPrivateKey from a password-protected PKCS#8 DER-encoded Ed25519 private key held in an IBinaryConvertible (byte password) and reports bytes consumed.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible value containing the encrypted DER-encoded PKCS#8 private key. |
password |
ReadOnlySpan<byte> |
The password bytes used to decrypt the key. |
bytesRead |
out int |
When this method returns, contains the number of bytes consumed from data. |
Returns — A new EddsaPrivateKey extracted from the decrypted PKCS#8 structure.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
The data cannot be decrypted or is not a valid PKCS#8 Ed25519 private key. |
public static EddsaPrivateKey ImportPem(ReadOnlySpan<char> data)Imports an EddsaPrivateKey from an unencrypted RFC 7468 PEM-encoded Ed25519 private key. The PEM label must be PRIVATE KEY.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<char> |
The PEM-encoded text containing the Ed25519 private key. |
Returns — A new EddsaPrivateKey imported from the PEM document.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data does not contain a valid PEM document, the label is not PRIVATE KEY, or the Base64 payload cannot be decoded. |
public static EddsaPrivateKey ImportPem(ReadOnlySpan<char> data, ReadOnlySpan<char> password)Decrypts and imports an EddsaPrivateKey from a password-protected RFC 7468 PEM-encoded Ed25519 private key using a character-array password. The PEM label must be ENCRYPTED PRIVATE KEY.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<char> |
The PEM-encoded text containing the encrypted Ed25519 private key. |
password |
ReadOnlySpan<char> |
The password used to decrypt the key. |
Returns — A new EddsaPrivateKey imported from the decrypted PEM document.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data does not contain a valid PEM document, the label is not ENCRYPTED PRIVATE KEY, the password is incorrect, or the payload cannot be decoded. |
public static EddsaPrivateKey ImportPem(ReadOnlySpan<char> data, ReadOnlySpan<byte> password)Decrypts and imports an EddsaPrivateKey from a password-protected RFC 7468 PEM-encoded Ed25519 private key using a byte-array password. The PEM label must be ENCRYPTED PRIVATE KEY.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<char> |
The PEM-encoded text containing the encrypted Ed25519 private key. |
password |
ReadOnlySpan<byte> |
The password bytes used to decrypt the key. |
Returns — A new EddsaPrivateKey imported from the decrypted PEM document.
Exceptions
| Exception | Condition |
|---|---|
CryptographicException |
data does not contain a valid PEM document, the label is not ENCRYPTED PRIVATE KEY, the password is incorrect, or the payload cannot be decoded. |
public static EddsaPrivateKey Parse(string value, IFormatProvider? provider = null)Parses a string into an EddsaPrivateKey. The default encoding is uppercase hexadecimal (Base16, invariant culture); pass an alternative IFormatProvider to accept other encodings such as Base58 or Base64.
| Parameter | Type | Description |
|---|---|---|
value |
string |
The string representation of the key to parse. |
provider |
IFormatProvider? |
An optional format provider that determines the encoding. Defaults to Base16FormatProvider.Invariant. |
Returns — A new EddsaPrivateKey decoded from the supplied string.
Exceptions
| Exception | Condition |
|---|---|
FormatException |
value is not in a valid format for the specified provider. |
public static EddsaPrivateKey Parse(ReadOnlySpan<char> value, IFormatProvider? provider = null)Parses a character span into an EddsaPrivateKey. The default encoding is uppercase hexadecimal (Base16, invariant culture); pass an alternative IFormatProvider to accept other encodings.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlySpan<char> |
The character span representation of the key to parse. |
provider |
IFormatProvider? |
An optional format provider that determines the encoding. Defaults to Base16FormatProvider.Invariant. |
Returns — A new EddsaPrivateKey decoded from the supplied span.
Exceptions
| Exception | Condition |
|---|---|
FormatException |
value is not in a valid format for the specified provider. |
public static bool TryParse(string? value, IFormatProvider? provider, out EddsaPrivateKey result)Attempts to parse a string into an EddsaPrivateKey without throwing on failure.
| Parameter | Type | Description |
|---|---|---|
value |
string? |
The string representation of the key to parse. |
provider |
IFormatProvider? |
An optional format provider that determines the encoding. Defaults to Base16FormatProvider.Invariant. |
result |
out EddsaPrivateKey |
When this method returns true, contains the parsed key; otherwise, a default instance. |
Returns — true if value was successfully parsed; otherwise, false.
public static bool TryParse(ReadOnlySpan<char> value, IFormatProvider? provider, out EddsaPrivateKey result)Attempts to parse a character span into an EddsaPrivateKey without throwing on failure.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlySpan<char> |
The character span representation of the key to parse. |
provider |
IFormatProvider? |
An optional format provider that determines the encoding. Defaults to Base16FormatProvider.Invariant. |
result |
out EddsaPrivateKey |
When this method returns true, contains the parsed key; otherwise, a default instance. |
Returns — true if value was successfully parsed; otherwise, false.
| Method | Returns | Description |
|---|---|---|
Export() |
byte[] |
Exports the raw 32-byte Ed25519 seed. |
ExportPkcs8() |
byte[] |
Exports the key as an unencrypted PKCS#8 DER-encoded byte array. |
ExportPkcs8(ReadOnlySpan<char>, PbeParameters) |
byte[] |
Exports the key as an encrypted PKCS#8 DER-encoded byte array (char password). |
ExportPkcs8(ReadOnlySpan<byte>, PbeParameters) |
byte[] |
Exports the key as an encrypted PKCS#8 DER-encoded byte array (byte password). |
ExportPkcs8Pem() |
string |
Exports the key as an unencrypted PKCS#8 PEM string (PRIVATE KEY). |
ExportPkcs8Pem(ReadOnlySpan<char>, PbeParameters) |
string |
Exports the key as an encrypted PKCS#8 PEM string (ENCRYPTED PRIVATE KEY, char password). |
ExportPkcs8Pem(ReadOnlySpan<byte>, PbeParameters) |
string |
Exports the key as an encrypted PKCS#8 PEM string (ENCRYPTED PRIVATE KEY, byte password). |
GetPublicKey() |
EddsaPublicKey |
Derives the corresponding Ed25519 public key from this private key's seed. |
SignData(ReadOnlySpan<byte>) |
byte[] |
Signs a message and returns the 64-byte Ed25519 signature. |
SignData(ReadOnlySpan<byte>, int, int) |
byte[] |
Signs a slice of a message and returns the 64-byte Ed25519 signature. |
SignData(Stream) |
byte[] |
Signs a stream (read to completion) and returns the 64-byte Ed25519 signature. |
SignData(IBinaryConvertible) |
byte[] |
Signs an IBinaryConvertible message and returns the 64-byte Ed25519 signature. |
ToNamedPrivateKey() |
NamedPrivateKey |
Returns a NamedPrivateKey wrapping this key with the algorithm name "EDDSA". |
For all other instance methods inherited from the base class (AsReadOnlyMemory, AsReadOnlySpan, Dispose, Equals, GetHashCode, ToString, and the equality operators), see PrivateKey.
public byte[] Export()Exports the raw 32-byte Ed25519 seed. The returned array is a fresh copy; callers should zero it after use.
Returns — A byte[] containing the raw Ed25519 seed.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
public byte[] ExportPkcs8()Exports the Ed25519 private key as an unencrypted PKCS#8 DER-encoded byte array. The seed is zeroed from intermediate buffers immediately after encoding.
Returns — A byte[] containing the DER-encoded PKCS#8 private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
public byte[] ExportPkcs8(ReadOnlySpan<char> password, PbeParameters parameters)Exports the Ed25519 private key as an encrypted PKCS#8 DER-encoded byte array protected by the supplied character-array password and PBE parameters.
| Parameter | Type | Description |
|---|---|---|
password |
ReadOnlySpan<char> |
The password used to encrypt the PKCS#8 structure. |
parameters |
PbeParameters |
The password-based encryption parameters, including the algorithm and iteration count. |
Returns — A byte[] containing the encrypted DER-encoded PKCS#8 private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
CryptographicException |
The encryption operation failed. |
public byte[] ExportPkcs8(ReadOnlySpan<byte> password, PbeParameters parameters)Exports the Ed25519 private key as an encrypted PKCS#8 DER-encoded byte array protected by the supplied byte-array password and PBE parameters.
| Parameter | Type | Description |
|---|---|---|
password |
ReadOnlySpan<byte> |
The password bytes used to encrypt the PKCS#8 structure. |
parameters |
PbeParameters |
The password-based encryption parameters, including the algorithm and iteration count. |
Returns — A byte[] containing the encrypted DER-encoded PKCS#8 private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
CryptographicException |
The encryption operation failed. |
public string ExportPkcs8Pem()Exports the Ed25519 private key as an unencrypted RFC 7468 PEM-encoded string. The PEM label is PRIVATE KEY.
Returns — A PEM string containing the unencrypted PKCS#8-encoded Ed25519 private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
public string ExportPkcs8Pem(ReadOnlySpan<char> password, PbeParameters parameters)Exports the Ed25519 private key as an encrypted RFC 7468 PEM-encoded string using a character-array password. The PEM label is ENCRYPTED PRIVATE KEY.
| Parameter | Type | Description |
|---|---|---|
password |
ReadOnlySpan<char> |
The password used to encrypt the PKCS#8 structure. |
parameters |
PbeParameters |
The password-based encryption parameters, including the algorithm and iteration count. |
Returns — A PEM string containing the encrypted PKCS#8-encoded Ed25519 private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
CryptographicException |
The encryption operation failed. |
public string ExportPkcs8Pem(ReadOnlySpan<byte> password, PbeParameters parameters)Exports the Ed25519 private key as an encrypted RFC 7468 PEM-encoded string using a byte-array password. The PEM label is ENCRYPTED PRIVATE KEY.
| Parameter | Type | Description |
|---|---|---|
password |
ReadOnlySpan<byte> |
The password bytes used to encrypt the PKCS#8 structure. |
parameters |
PbeParameters |
The password-based encryption parameters, including the algorithm and iteration count. |
Returns — A PEM string containing the encrypted PKCS#8-encoded Ed25519 private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
CryptographicException |
The encryption operation failed. |
public EddsaPublicKey GetPublicKey()Derives the 32-byte Ed25519 public key from this private key's seed using the Ed25519 scalar-multiplication formula. The public key is derived the first time it is needed (by this method or by signing) and then reused by the same instance, because it is not secret and the seed never changes. The decrypted seed is zeroed from the intermediate stack buffer immediately after use.
Returns — A new EddsaPublicKey corresponding to this private key.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
public byte[] SignData(ReadOnlySpan<byte> data)Signs the message and returns the 64-byte Ed25519 signature. EdDSA is deterministic: signing the same message with the same key always produces the same signature. No separate hash algorithm is needed — Ed25519 applies SHA-512 internally.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The message bytes to sign. |
Returns — A 64-byte byte[] containing the Ed25519 signature.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
public byte[] SignData(ReadOnlySpan<byte> data, int offset, int count)Signs a slice of the message defined by offset and count, and returns the 64-byte Ed25519 signature.
| Parameter | Type | Description |
|---|---|---|
data |
ReadOnlySpan<byte> |
The buffer containing the message bytes. |
offset |
int |
The zero-based offset into data at which the message begins. |
count |
int |
The number of bytes in data to sign. |
Returns — A 64-byte byte[] containing the Ed25519 signature.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
ArgumentOutOfRangeException |
offset or count is outside the bounds of data. |
public byte[] SignData(Stream data)Signs a stream and returns the 64-byte Ed25519 signature. The stream is read to completion into an in-memory buffer before signing, because PureEdDSA requires the entire message during the nonce-derivation and challenge phases.
| Parameter | Type | Description |
|---|---|---|
data |
Stream |
The stream containing the message bytes to sign. |
Returns — A 64-byte byte[] containing the Ed25519 signature.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
IOException |
An I/O error occurred while reading data. |
public byte[] SignData(IBinaryConvertible data)Signs an IBinaryConvertible message and returns the 64-byte Ed25519 signature.
| Parameter | Type | Description |
|---|---|---|
data |
IBinaryConvertible |
The binary-convertible message to sign. |
Returns — A 64-byte byte[] containing the Ed25519 signature.
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
public override NamedPrivateKey ToNamedPrivateKey()Creates a new NamedPrivateKey from this EddsaPrivateKey, using the algorithm identifier "EDDSA".
Returns — A NamedPrivateKey pairing this instance with the algorithm name "EDDSA".
Exceptions
| Exception | Condition |
|---|---|
ObjectDisposedException |
The current EddsaPrivateKey has been disposed. |
| Operator | Description |
|---|---|
implicit operator EddsaPrivateKey(ReadOnlySpan<byte>) |
Creates an EddsaPrivateKey from a ReadOnlySpan<byte>. |
implicit operator EddsaPrivateKey(ReadOnlyMemory<byte>) |
Creates an EddsaPrivateKey from a ReadOnlyMemory<byte>. |
implicit operator EddsaPrivateKey(ReadOnlySequence<byte>) |
Creates an EddsaPrivateKey from a ReadOnlySequence<byte>. |
public static implicit operator EddsaPrivateKey(ReadOnlySpan<byte> value)Creates a new EddsaPrivateKey from the specified ReadOnlySpan<byte> value.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlySpan<byte> |
The span from which to create a new EddsaPrivateKey instance. |
public static implicit operator EddsaPrivateKey(ReadOnlyMemory<byte> value)Creates a new EddsaPrivateKey from the specified ReadOnlyMemory<byte> value.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlyMemory<byte> |
The memory region from which to create a new EddsaPrivateKey instance. |
public static implicit operator EddsaPrivateKey(ReadOnlySequence<byte> value)Creates a new EddsaPrivateKey from the specified ReadOnlySequence<byte> value.
| Parameter | Type | Description |
|---|---|---|
value |
ReadOnlySequence<byte> |
The byte sequence from which to create a new EddsaPrivateKey instance. |
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