Skip to content

OnixLabs.Security.Cryptography.DigitalSignatureAndPublicKey

matthew edited this page May 27, 2026 · 1 revision

DigitalSignatureAndPublicKey Record Struct

Represents a pair consisting of a cryptographic digital signature and the named public key required to verify it.

Namespace OnixLabs.Security.Cryptography
Assembly OnixLabs.Security.Cryptography.dll (NuGet)
Inheritance object → ValueType → DigitalSignatureAndPublicKey
Implements IEquatable<DigitalSignatureAndPublicKey>

Definition

public readonly record struct DigitalSignatureAndPublicKey(DigitalSignature Signature, NamedPublicKey Key);

Remarks

DigitalSignatureAndPublicKey is a convenience readonly record struct that keeps a DigitalSignature and its associated NamedPublicKey together as a single value. This is useful when a signing operation must return both the signature bytes and the public key that can be used to verify them — for example, when recording signed artefacts that may be verified later without a separate key lookup.

Because this is a readonly record struct, the compiler synthesizes value-equality, GetHashCode, ToString, and deconstruction automatically. Two DigitalSignatureAndPublicKey values are equal when both their Signature and Key components are equal.

The positional record syntax means the constructor parameters Signature and Key are also auto-generated { get; init; } properties.

Examples

Bundling a signature and key after signing

using OnixLabs.Security.Cryptography;

EcdsaPrivateKey privateKey = EcdsaPrivateKey.Create();
byte[] data = System.Text.Encoding.UTF8.GetBytes("important document");

DigitalSignature signature = privateKey.SignData(data);
NamedPublicKey publicKey = privateKey.GetPublicKey();

// Bundle the two together for storage or transmission.
var bundle = new DigitalSignatureAndPublicKey(signature, publicKey);

// Later: verify using the bundled key.
bool valid = bundle.Key.IsValidSignature(bundle.Signature, data);
Console.WriteLine(valid); // True

// Deconstruct using positional pattern.
var (sig, key) = bundle;

Constructors

Constructor Description
DigitalSignatureAndPublicKey(DigitalSignature, NamedPublicKey) Initializes a new instance with the specified signature and key.

DigitalSignatureAndPublicKey(DigitalSignature, NamedPublicKey)

public DigitalSignatureAndPublicKey(DigitalSignature Signature, NamedPublicKey Key)

Initializes a new instance of the DigitalSignatureAndPublicKey record struct.

Parameter Type Description
Signature DigitalSignature The cryptographic digital signature.
Key NamedPublicKey The named public key associated with the signature.

Properties

Property Type Description
Signature DigitalSignature Gets the cryptographic digital signature.
Key NamedPublicKey Gets the named public key associated with the signature.

Signature

public DigitalSignature Signature { get; init; }

Gets the DigitalSignature component of this pair.


Key

public NamedPublicKey Key { get; init; }

Gets the NamedPublicKey component of this pair. A NamedPublicKey bundles a public key with its algorithm name, providing the information needed to select the correct verification algorithm.

See Also

ONIXLabs .NET Library


Clone this wiki locally