Skip to content

OnixLabs.Security.Cryptography.EcdsaPublicKey

matthew edited this page May 27, 2026 · 2 revisions

EcdsaPublicKey Class

Represents an ECDSA (Elliptic Curve Digital Signature Algorithm) cryptographic public key, used to verify digital signatures produced by the corresponding private key.

Namespace OnixLabs.Security.Cryptography
Assembly OnixLabs.Security.Cryptography.dll (NuGet)
Inheritance object → PublicKey → EcdsaPublicKey
Implements IEcdsaPublicKey, ISpanParsable<EcdsaPublicKey>, IPublicKeyImportable<EcdsaPublicKey>, IPublicKeyExportable, ICryptoPrimitive<PublicKey>, IValueEquatable<PublicKey>, IEquatable<PublicKey>, IBinaryConvertible

Definition

public sealed partial class EcdsaPublicKey : PublicKey, IEcdsaPublicKey, ISpanParsable<EcdsaPublicKey>

Remarks

EcdsaPublicKey is the concrete ECDSA public-key type. It stores key material as an X.509 SubjectPublicKeyInfo (SPKI) DER structure in the protected byte[] it inherits from PublicKey. Unlike its private-key counterpart, EcdsaPublicKey does not implement IDisposable because public keys carry no sensitive material and do not require secure erasure.

Verification. Two families of verification operation are available, each returning a bool or throwing on failure:

  • IsDataValid — hashes the supplied input data and checks whether the provided signature is valid. Returns true or false without throwing.
  • VerifyData — same as IsDataValid but throws CryptographicException if the signature is not valid. Use this for fail-fast paths where an invalid signature should be treated as an exceptional condition.

Both families also have hash variants (IsHashValid / VerifyHash) that accept a pre-computed hash value instead of raw data. All overloads accept the signature as either a raw ReadOnlySpan<byte> or a DigitalSignature value, the data source as a ReadOnlySpan<byte>, byte-range slice, Stream, or IBinaryConvertible, and the hash algorithm as either a HashAlgorithm instance or a HashAlgorithmName. An optional DSASignatureFormat parameter selects between IEEE P1363 and DER (ASN.1) signature encoding.

Obtaining instances. The most common way to obtain an EcdsaPublicKey is to derive it from the corresponding EcdsaPrivateKey via privateKey.GetPublicKey(). Alternatively, existing key material can be imported via Import (raw SPKI DER bytes) or ImportPem (RFC 7468 PEM text). A hex-encoded key can be round-tripped via Parse / TryParse.

Export formats. The key can be exported in two formats:

Method Format
Export() Raw SPKI DER binary (SubjectPublicKeyInfo)
ExportPem() RFC 7468 PEM (PUBLIC KEY)

Named key. Call ToNamedPublicKey() to wrap this key in a NamedPublicKey that carries the algorithm name "ECDSA" alongside the key bytes.

Note EcdsaPublicKey inherits value semantics from PublicKey: equality and hash codes are based on the key bytes, not reference identity. Equality comparisons use constant-time byte comparison to prevent timing side-channel attacks.

Examples

Deriving a public key and verifying a signature

using System.Security.Cryptography;
using OnixLabs.Security.Cryptography;

using EcdsaPrivateKey privateKey = EcdsaPrivateKey.Create();
EcdsaPublicKey publicKey = privateKey.GetPublicKey();

byte[] data = System.Text.Encoding.UTF8.GetBytes("Hello, ONIXLabs!");
byte[] signature = privateKey.SignData(data, HashAlgorithmName.SHA256);

// Returns true/false without throwing.
bool valid = publicKey.IsDataValid(signature, data, HashAlgorithmName.SHA256);
Console.WriteLine(valid); // True

Verifying with VerifyData (throws on failure)

using System.Security.Cryptography;
using OnixLabs.Security.Cryptography;

using EcdsaPrivateKey privateKey = EcdsaPrivateKey.Create();
EcdsaPublicKey publicKey = privateKey.GetPublicKey();

byte[] data = System.Text.Encoding.UTF8.GetBytes("Hello, ONIXLabs!");
byte[] signature = privateKey.SignData(data, HashAlgorithmName.SHA256);

// Throws CryptographicException if the signature is invalid.
publicKey.VerifyData(signature, data, HashAlgorithmName.SHA256);
Console.WriteLine("Signature is valid.");

Importing a public key from PEM

using OnixLabs.Security.Cryptography;

// Assume pemText contains a PUBLIC KEY PEM block.
string pemText = "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----";
EcdsaPublicKey publicKey = EcdsaPublicKey.ImportPem(pemText);

Computing a key fingerprint

using System.Security.Cryptography;
using OnixLabs.Security.Cryptography;

using EcdsaPrivateKey privateKey = EcdsaPrivateKey.Create();
EcdsaPublicKey publicKey = privateKey.GetPublicKey();

Hash fingerprint = publicKey.GetHash(SHA256.Create());
Console.WriteLine(fingerprint); // SHA2-256:<hex>

Wrapping in a NamedPublicKey

using OnixLabs.Security.Cryptography;

using EcdsaPrivateKey privateKey = EcdsaPrivateKey.Create();
EcdsaPublicKey publicKey = privateKey.GetPublicKey();

NamedPublicKey named = publicKey.ToNamedPublicKey();
Console.WriteLine(named.AlgorithmName); // ECDSA
Console.WriteLine(named);               // ECDSA:<hex-encoded key bytes>

Constructors

Constructor Description
EcdsaPublicKey(ReadOnlySpan<byte>) Initializes a new instance from a span of bytes.
EcdsaPublicKey(ReadOnlyMemory<byte>) Initializes a new instance from a memory region.
EcdsaPublicKey(ReadOnlySequence<byte>) Initializes a new instance from a byte sequence.

EcdsaPublicKey(ReadOnlySpan<byte>)

public EcdsaPublicKey(ReadOnlySpan<byte> keyData)

Initializes a new instance of the EcdsaPublicKey class from a span of bytes. The provided span is copied to an internal array; the span itself is not retained.

Parameter Type Description
keyData ReadOnlySpan<byte> The underlying key data of the ECDSA cryptographic public key.

EcdsaPublicKey(ReadOnlyMemory<byte>)

public EcdsaPublicKey(ReadOnlyMemory<byte> keyData)

Initializes a new instance of the EcdsaPublicKey class from a memory region. The provided memory region is copied to an internal array; the original memory is not retained.

Parameter Type Description
keyData ReadOnlyMemory<byte> The underlying key data of the ECDSA cryptographic public key.

EcdsaPublicKey(ReadOnlySequence<byte>)

public EcdsaPublicKey(ReadOnlySequence<byte> keyData)

Initializes a new instance of the EcdsaPublicKey class from a byte sequence. The provided byte sequence is copied to an internal array; the original sequence is not retained.

Parameter Type Description
keyData ReadOnlySequence<byte> The underlying key data of the ECDSA cryptographic public key.

Static Methods

Method Returns Description
Import(ReadOnlySpan<byte>) EcdsaPublicKey Imports a key from raw SPKI DER bytes.
Import(ReadOnlySpan<byte>, out int) EcdsaPublicKey Imports a key from raw SPKI DER bytes; reports bytes read.
Import(IBinaryConvertible) EcdsaPublicKey Imports a key from an IBinaryConvertible.
Import(IBinaryConvertible, out int) EcdsaPublicKey Imports a key from an IBinaryConvertible; reports bytes read.
ImportPem(ReadOnlySpan<char>) EcdsaPublicKey Imports a key from RFC 7468 PEM text.
ImportPem(ReadOnlySpan<char>, ReadOnlySpan<char>) EcdsaPublicKey Imports a key from encrypted PEM text using a char-based password.
ImportPem(ReadOnlySpan<char>, ReadOnlySpan<byte>) EcdsaPublicKey Imports a key from encrypted PEM text using a byte-based password.
Parse(string, IFormatProvider?) EcdsaPublicKey Parses a base-encoded string into an EcdsaPublicKey.
Parse(ReadOnlySpan<char>, IFormatProvider?) EcdsaPublicKey Parses a base-encoded character span into an EcdsaPublicKey.
TryParse(string?, IFormatProvider?, out EcdsaPublicKey) bool Attempts to parse a base-encoded string into an EcdsaPublicKey.
TryParse(ReadOnlySpan<char>, IFormatProvider?, out EcdsaPublicKey) bool Attempts to parse a base-encoded character span into an EcdsaPublicKey.

Import overloads

public static EcdsaPublicKey Import(ReadOnlySpan<byte> data)
public static EcdsaPublicKey Import(ReadOnlySpan<byte> data, out int bytesRead)
public static EcdsaPublicKey Import(IBinaryConvertible data)
public static EcdsaPublicKey Import(IBinaryConvertible data, out int bytesRead)

Imports an ECDSA public key from raw X.509 SubjectPublicKeyInfo (SPKI) DER-encoded binary data.

Parameter Type Description
data ReadOnlySpan<byte> or IBinaryConvertible The SPKI DER-encoded public key data to import.
bytesRead out int (bytesRead overloads) Receives the number of bytes consumed from data.

Returns — A new EcdsaPublicKey instance.

Exceptions

Exception Condition
CryptographicException data does not contain a valid SPKI-encoded ECDSA public key.

ImportPem overloads

public static EcdsaPublicKey ImportPem(ReadOnlySpan<char> data)
public static EcdsaPublicKey ImportPem(ReadOnlySpan<char> data, ReadOnlySpan<char> password)
public static EcdsaPublicKey ImportPem(ReadOnlySpan<char> data, ReadOnlySpan<byte> password)

Imports an ECDSA public key from RFC 7468 PEM-encoded text. The PEM label must be PUBLIC KEY (SubjectPublicKeyInfo). The two-argument overloads are provided for symmetry with the private-key API and apply password-based decryption when the PEM block requires it.

Parameter Type Description
data ReadOnlySpan<char> The RFC 7468 PEM-encoded public key text to import.
password ReadOnlySpan<char> or ReadOnlySpan<byte> (encrypted overloads) The password required for password-based decryption, if applicable.

Returns — A new EcdsaPublicKey instance.

Exceptions

Exception Condition
CryptographicException data is not a valid PEM-encoded ECDSA public key.

Parse(string, IFormatProvider?)

public static EcdsaPublicKey Parse(string value, IFormatProvider? provider = null)

Parses a base-encoded string representation of an EcdsaPublicKey. When provider is null, Base16FormatProvider.Invariant (hexadecimal) is used.

Parameter Type Description
value string The base-encoded string to parse.
provider IFormatProvider? The format provider that determines the encoding. Defaults to hexadecimal when null.

Returns — A new EcdsaPublicKey instance.

Exceptions

Exception Condition
FormatException value is not a valid base-encoded string for the specified provider.

Parse(ReadOnlySpan<char>, IFormatProvider?)

public static EcdsaPublicKey Parse(ReadOnlySpan<char> value, IFormatProvider? provider = null)

Parses a base-encoded character span representation of an EcdsaPublicKey. When provider is null, Base16FormatProvider.Invariant (hexadecimal) is used.

Parameter Type Description
value ReadOnlySpan<char> The base-encoded character span to parse.
provider IFormatProvider? The format provider that determines the encoding. Defaults to hexadecimal when null.

Returns — A new EcdsaPublicKey instance.

Exceptions

Exception Condition
FormatException value is not a valid base-encoded span for the specified provider.

TryParse(string?, IFormatProvider?, out EcdsaPublicKey)

public static bool TryParse(string? value, IFormatProvider? provider, out EcdsaPublicKey result)

Attempts to parse a base-encoded string representation of an EcdsaPublicKey without throwing on failure. When provider is null, Base16FormatProvider.Invariant is used.

Parameter Type Description
value string? The base-encoded string to parse.
provider IFormatProvider? The format provider that determines the encoding.
result out EcdsaPublicKey When this method returns, contains the parsed EcdsaPublicKey, or an instance wrapping the decoded bytes on partial failure.

Returns — true if value was decoded successfully; otherwise, false.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out EcdsaPublicKey)

public static bool TryParse(ReadOnlySpan<char> value, IFormatProvider? provider, out EcdsaPublicKey result)

Attempts to parse a base-encoded character span representation of an EcdsaPublicKey without throwing on failure. When provider is null, Base16FormatProvider.Invariant is used.

Parameter Type Description
value ReadOnlySpan<char> The base-encoded character span to parse.
provider IFormatProvider? The format provider that determines the encoding.
result out EcdsaPublicKey When this method returns, contains the parsed EcdsaPublicKey, or an instance wrapping the decoded bytes on partial failure.

Returns — true if value was decoded successfully; otherwise, false.

Instance Methods

Method Returns Description
IsDataValid(ReadOnlySpan<byte>, ReadOnlySpan<byte>, HashAlgorithm, DSASignatureFormat) bool Checks if a span of data was signed with the given raw signature (HashAlgorithm).
IsDataValid(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, HashAlgorithm, DSASignatureFormat) bool Checks if a byte-range slice was signed with the given raw signature (HashAlgorithm).
IsDataValid(ReadOnlySpan<byte>, Stream, HashAlgorithm, DSASignatureFormat) bool Checks if a stream was signed with the given raw signature (HashAlgorithm).
IsDataValid(ReadOnlySpan<byte>, IBinaryConvertible, HashAlgorithm, DSASignatureFormat) bool Checks if an IBinaryConvertible was signed with the given raw signature (HashAlgorithm).
IsDataValid(ReadOnlySpan<byte>, ReadOnlySpan<byte>, HashAlgorithmName, DSASignatureFormat) bool Checks if a span of data was signed with the given raw signature (HashAlgorithmName).
IsDataValid(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, HashAlgorithmName, DSASignatureFormat) bool Checks if a byte-range slice was signed with the given raw signature (HashAlgorithmName).
IsDataValid(ReadOnlySpan<byte>, Stream, HashAlgorithmName, DSASignatureFormat) bool Checks if a stream was signed with the given raw signature (HashAlgorithmName).
IsDataValid(ReadOnlySpan<byte>, IBinaryConvertible, HashAlgorithmName, DSASignatureFormat) bool Checks if an IBinaryConvertible was signed with the given raw signature (HashAlgorithmName).
IsDataValid(DigitalSignature, ReadOnlySpan<byte>, HashAlgorithm, DSASignatureFormat) bool Checks if a span of data was signed with the given DigitalSignature (HashAlgorithm).
IsDataValid(DigitalSignature, ReadOnlySpan<byte>, int, int, HashAlgorithm, DSASignatureFormat) bool Checks if a byte-range slice was signed with the given DigitalSignature (HashAlgorithm).
IsDataValid(DigitalSignature, Stream, HashAlgorithm, DSASignatureFormat) bool Checks if a stream was signed with the given DigitalSignature (HashAlgorithm).
IsDataValid(DigitalSignature, IBinaryConvertible, HashAlgorithm, DSASignatureFormat) bool Checks if an IBinaryConvertible was signed with the given DigitalSignature (HashAlgorithm).
IsDataValid(DigitalSignature, ReadOnlySpan<byte>, HashAlgorithmName, DSASignatureFormat) bool Checks if a span of data was signed with the given DigitalSignature (HashAlgorithmName).
IsDataValid(DigitalSignature, ReadOnlySpan<byte>, int, int, HashAlgorithmName, DSASignatureFormat) bool Checks if a byte-range slice was signed with the given DigitalSignature (HashAlgorithmName).
IsDataValid(DigitalSignature, Stream, HashAlgorithmName, DSASignatureFormat) bool Checks if a stream was signed with the given DigitalSignature (HashAlgorithmName).
IsDataValid(DigitalSignature, IBinaryConvertible, HashAlgorithmName, DSASignatureFormat) bool Checks if an IBinaryConvertible was signed with the given DigitalSignature (HashAlgorithmName).
IsHashValid(ReadOnlySpan<byte>, Hash, DSASignatureFormat) bool Checks if a pre-computed Hash was signed with the given raw signature.
IsHashValid(ReadOnlySpan<byte>, ReadOnlySpan<byte>, DSASignatureFormat) bool Checks if a pre-computed hash span was signed with the given raw signature.
IsHashValid(DigitalSignature, Hash, DSASignatureFormat) bool Checks if a pre-computed Hash was signed with the given DigitalSignature.
IsHashValid(DigitalSignature, ReadOnlySpan<byte>, DSASignatureFormat) bool Checks if a pre-computed hash span was signed with the given DigitalSignature.
VerifyData(ReadOnlySpan<byte>, ReadOnlySpan<byte>, HashAlgorithm, DSASignatureFormat) void Verifies data against a raw signature (HashAlgorithm); throws on failure.
VerifyData(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, HashAlgorithm, DSASignatureFormat) void Verifies a byte-range slice against a raw signature (HashAlgorithm); throws on failure.
VerifyData(ReadOnlySpan<byte>, Stream, HashAlgorithm, DSASignatureFormat) void Verifies a stream against a raw signature (HashAlgorithm); throws on failure.
VerifyData(ReadOnlySpan<byte>, IBinaryConvertible, HashAlgorithm, DSASignatureFormat) void Verifies an IBinaryConvertible against a raw signature (HashAlgorithm); throws on failure.
VerifyData(ReadOnlySpan<byte>, ReadOnlySpan<byte>, HashAlgorithmName, DSASignatureFormat) void Verifies data against a raw signature (HashAlgorithmName); throws on failure.
VerifyData(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, HashAlgorithmName, DSASignatureFormat) void Verifies a byte-range slice against a raw signature (HashAlgorithmName); throws on failure.
VerifyData(ReadOnlySpan<byte>, Stream, HashAlgorithmName, DSASignatureFormat) void Verifies a stream against a raw signature (HashAlgorithmName); throws on failure.
VerifyData(ReadOnlySpan<byte>, IBinaryConvertible, HashAlgorithmName, DSASignatureFormat) void Verifies an IBinaryConvertible against a raw signature (HashAlgorithmName); throws on failure.
VerifyData(DigitalSignature, ReadOnlySpan<byte>, HashAlgorithm, DSASignatureFormat) void Verifies data against a DigitalSignature (HashAlgorithm); throws on failure.
VerifyData(DigitalSignature, ReadOnlySpan<byte>, int, int, HashAlgorithm, DSASignatureFormat) void Verifies a byte-range slice against a DigitalSignature (HashAlgorithm); throws on failure.
VerifyData(DigitalSignature, Stream, HashAlgorithm, DSASignatureFormat) void Verifies a stream against a DigitalSignature (HashAlgorithm); throws on failure.
VerifyData(DigitalSignature, IBinaryConvertible, HashAlgorithm, DSASignatureFormat) void Verifies an IBinaryConvertible against a DigitalSignature (HashAlgorithm); throws on failure.
VerifyData(DigitalSignature, ReadOnlySpan<byte>, HashAlgorithmName, DSASignatureFormat) void Verifies data against a DigitalSignature (HashAlgorithmName); throws on failure.
VerifyData(DigitalSignature, ReadOnlySpan<byte>, int, int, HashAlgorithmName, DSASignatureFormat) void Verifies a byte-range slice against a DigitalSignature (HashAlgorithmName); throws on failure.
VerifyData(DigitalSignature, Stream, HashAlgorithmName, DSASignatureFormat) void Verifies a stream against a DigitalSignature (HashAlgorithmName); throws on failure.
VerifyData(DigitalSignature, IBinaryConvertible, HashAlgorithmName, DSASignatureFormat) void Verifies an IBinaryConvertible against a DigitalSignature (HashAlgorithmName); throws on failure.
VerifyHash(ReadOnlySpan<byte>, Hash, DSASignatureFormat) void Verifies a pre-computed Hash against a raw signature; throws on failure.
VerifyHash(ReadOnlySpan<byte>, ReadOnlySpan<byte>, DSASignatureFormat) void Verifies a pre-computed hash span against a raw signature; throws on failure.
VerifyHash(DigitalSignature, Hash, DSASignatureFormat) void Verifies a pre-computed Hash against a DigitalSignature; throws on failure.
VerifyHash(DigitalSignature, ReadOnlySpan<byte>, DSASignatureFormat) void Verifies a pre-computed hash span against a DigitalSignature; throws on failure.
Export() byte[] Exports the key in raw SPKI DER binary format.
ExportPem() string Exports the key in RFC 7468 PEM format (PUBLIC KEY).
ToNamedPublicKey() NamedPublicKey Creates a NamedPublicKey with algorithm name "ECDSA".

For inherited members (AsReadOnlyMemory, AsReadOnlySpan, Equals, GetHash, GetHashCode, ToString), see PublicKey.


IsDataValid overloads

public bool IsDataValid(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, Stream data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, Stream data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(ReadOnlySpan<byte> signature, IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, ReadOnlySpan<byte> data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, ReadOnlySpan<byte> data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default)

Hashes the specified input data and checks whether the provided signature is a valid ECDSA signature over that hash. Returns true or false; does not throw if the signature is invalid.

Parameter Type Description
signature ReadOnlySpan<byte> or DigitalSignature The digital signature to verify.
data ReadOnlySpan<byte>, Stream, or IBinaryConvertible The input data to hash and verify against the signature.
offset int (slice overloads) The offset into the span from which to begin reading.
count int (slice overloads) The number of bytes to read from the span.
algorithm HashAlgorithm or HashAlgorithmName The hash algorithm used to hash the input data before verification.
format DSASignatureFormat The digital signature format. Defaults to DSASignatureFormat.IeeeP1363FixedFieldConcatenation.

Returns — true if the signature is valid for the specified data; otherwise, false.

Exceptions

Exception Condition
CryptographicException The underlying key data is not a valid ECDSA public key.

IsHashValid overloads

public bool IsHashValid(ReadOnlySpan<byte> signature, Hash hash, DSASignatureFormat format = default)
public bool IsHashValid(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> hash, DSASignatureFormat format = default)
public bool IsHashValid(DigitalSignature signature, Hash hash, DSASignatureFormat format = default)
public bool IsHashValid(DigitalSignature signature, ReadOnlySpan<byte> hash, DSASignatureFormat format = default)

Checks whether the provided signature is a valid ECDSA signature over the specified pre-computed hash value. No additional hashing is performed. Returns true or false; does not throw if the signature is invalid.

Parameter Type Description
signature ReadOnlySpan<byte> or DigitalSignature The digital signature to verify.
hash Hash or ReadOnlySpan<byte> The pre-computed hash value to verify against the signature.
format DSASignatureFormat The digital signature format. Defaults to DSASignatureFormat.IeeeP1363FixedFieldConcatenation.

Returns — true if the signature is valid for the specified hash; otherwise, false.

Exceptions

Exception Condition
CryptographicException The underlying key data is not a valid ECDSA public key.

VerifyData overloads

public void VerifyData(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, Stream data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, Stream data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(ReadOnlySpan<byte> signature, IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, ReadOnlySpan<byte> data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, Stream data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, ReadOnlySpan<byte> data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, ReadOnlySpan<byte> data, int offset, int count, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, Stream data, HashAlgorithmName algorithm, DSASignatureFormat format = default)
public void VerifyData(DigitalSignature signature, IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default)

Hashes the specified input data and verifies that the provided signature is valid. Throws CryptographicException if the signature is invalid. Use IsDataValid instead when a non-exceptional false return is preferable.

Parameter Type Description
signature ReadOnlySpan<byte> or DigitalSignature The digital signature to verify.
data ReadOnlySpan<byte>, Stream, or IBinaryConvertible The input data to hash and verify against the signature.
offset int (slice overloads) The offset into the span from which to begin reading.
count int (slice overloads) The number of bytes to read from the span.
algorithm HashAlgorithm or HashAlgorithmName The hash algorithm used to hash the input data before verification.
format DSASignatureFormat The digital signature format. Defaults to DSASignatureFormat.IeeeP1363FixedFieldConcatenation.

Exceptions

Exception Condition
CryptographicException The signature is not valid for the specified data, or the underlying key data is not a valid ECDSA public key.

VerifyHash overloads

public void VerifyHash(ReadOnlySpan<byte> signature, Hash hash, DSASignatureFormat format = default)
public void VerifyHash(ReadOnlySpan<byte> signature, ReadOnlySpan<byte> hash, DSASignatureFormat format = default)
public void VerifyHash(DigitalSignature signature, Hash hash, DSASignatureFormat format = default)
public void VerifyHash(DigitalSignature signature, ReadOnlySpan<byte> hash, DSASignatureFormat format = default)

Verifies that the provided signature is valid for the specified pre-computed hash value. No additional hashing is performed. Throws CryptographicException if the signature is invalid. Use IsHashValid instead when a non-exceptional false return is preferable.

Parameter Type Description
signature ReadOnlySpan<byte> or DigitalSignature The digital signature to verify.
hash Hash or ReadOnlySpan<byte> The pre-computed hash value to verify against the signature.
format DSASignatureFormat The digital signature format. Defaults to DSASignatureFormat.IeeeP1363FixedFieldConcatenation.

Exceptions

Exception Condition
CryptographicException The signature is not valid for the specified hash, or the underlying key data is not a valid ECDSA public key.

Export()

public byte[] Export()

Exports the ECDSA public key in its raw X.509 SubjectPublicKeyInfo (SPKI) DER binary format. This is the same format used internally to store the key bytes, and is importable via Import.

Returns — A byte[] containing the SPKI DER-encoded public key.

Exceptions

Exception Condition
CryptographicException The key could not be exported.

ExportPem()

public string ExportPem()

Exports the ECDSA public key in RFC 7468 PEM format, producing a PUBLIC KEY PEM block (SubjectPublicKeyInfo encoding).

Returns — A string containing the RFC 7468 PEM-encoded public key.

Exceptions

Exception Condition
CryptographicException The key could not be exported.

ToNamedPublicKey()

public override NamedPublicKey ToNamedPublicKey()

Creates a new NamedPublicKey from this instance with the algorithm name "ECDSA". The named key carries both the raw key bytes and the algorithm identifier, making it self-describing for storage and transmission.

Returns — A NamedPublicKey pairing this instance with the name "ECDSA".

Conversion Operators

Operator From Description
implicit operator EcdsaPublicKey ReadOnlySpan<byte> Creates a new EcdsaPublicKey from a ReadOnlySpan<byte>.
implicit operator EcdsaPublicKey ReadOnlyMemory<byte> Creates a new EcdsaPublicKey from a ReadOnlyMemory<byte>.
implicit operator EcdsaPublicKey ReadOnlySequence<byte> Creates a new EcdsaPublicKey from a ReadOnlySequence<byte>.

See Also

ONIXLabs .NET Library


Clone this wiki locally