Table of Contents

Class KeyExtensions

Namespace
Yubico.YubiKey.Piv.Converters
Assembly
Yubico.YubiKey.dll

Extension methods for encoding cryptographic key parameters into PIV-compatible formats.

public static class KeyExtensions
Inheritance
object
KeyExtensions

Remarks

This class provides extension methods for both public and private key parameters, supporting RSA, EC (Elliptic Curve), and Curve25519 key types. The encoded formats follow the Personal Identity Verification (PIV) specifications.

Methods

EncodeAsPiv(IPrivateKey)

Encodes a private key into the PIV format.

public static Memory<byte> EncodeAsPiv(this IPrivateKey parameters)

Parameters

parameters IPrivateKey

The private key parameters to encode.

Returns

Memory<byte>

A BER encoded byte array containing the encoded private key.

Remarks

This method returns a newly allocated array containing sensitive information.

Exceptions

ArgumentException

Thrown when the key type is not supported or when RSA key components have invalid lengths.

EncodeAsPiv(IPublicKey)

Encodes a public key into the PIV format.

public static Memory<byte> EncodeAsPiv(this IPublicKey parameters)

Parameters

parameters IPublicKey

The public key parameters to encode.

Returns

Memory<byte>

A BER encoded byte array containing the encoded public key.

Exceptions

ArgumentException

Thrown when the key type is not supported.