Table of Contents

Class ECPrivateKey

Namespace
Yubico.YubiKey.Cryptography
Assembly
Yubico.YubiKey.dll

Represents the parameters for an Elliptic Curve (EC) private key.

public class ECPrivateKey : PrivateKey, IPrivateKey, IKeyBase
Inheritance
object
ECPrivateKey
Implements
Inherited Members
Extension Methods

Remarks

This class encapsulates the parameters specific to EC private keys and provides factory methods for creating instances from EC parameters or DER-encoded data.

Constructors

ECPrivateKey(ECDsa)

Initializes a new instance of the ECPrivateKey class using a System.Security.Cryptography.ECDsa object.

protected ECPrivateKey(ECDsa ecdsaObject)

Parameters

ecdsaObject ECDsa

The ECDsa object.

Remarks

It exports the parameters from the ECDsa object and deep copy the parameters from the ECParameters object.

ECPrivateKey(ECParameters)

Initializes a new instance of the ECPrivateKey class. It is a wrapper for the System.Security.Cryptography.ECParameters class.

protected ECPrivateKey(ECParameters parameters)

Parameters

parameters ECParameters

The EC parameters.

Remarks

This constructor is used to create an instance from a System.Security.Cryptography.ECParameters object. It will deep copy the parameters from the ECParameters object.

Exceptions

ArgumentException

Thrown when parameters do not contain D value.

Properties

KeyDefinition

Gets the key definition associated with this RSA private key.

public KeyDefinition KeyDefinition { get; }

Property Value

KeyDefinition

A KeyDefinition object that describes the key's properties, including its type and length.

KeyType

Gets the type of the cryptographic key.

public override KeyType KeyType { get; }

Property Value

KeyType

A KeyType value indicating the type of the key.

Parameters

Gets the Elliptic Curve parameters associated with this instance.

public ECParameters Parameters { get; }

Property Value

ECParameters

An System.Security.Cryptography.ECParameters structure containing the curve parameters, key, and other cryptographic elements needed for EC operations.

Methods

Clear()

Clears the buffers containing private key data.

public override void Clear()

CreateFromParameters(ECParameters)

Creates an instance of ECPrivateKey from the given parameters.

public static ECPrivateKey CreateFromParameters(ECParameters parameters)

Parameters

parameters ECParameters

The parameters to create the key from.

Returns

ECPrivateKey

An instance of ECPrivateKey.

CreateFromPkcs8(ReadOnlyMemory<byte>)

Creates a new instance of ECPrivateKey from a DER-encoded private key.

public static ECPrivateKey CreateFromPkcs8(ReadOnlyMemory<byte> encodedKey)

Parameters

encodedKey ReadOnlyMemory<byte>

The DER-encoded private key.

Returns

ECPrivateKey

A new instance of ECPrivateKey.

Exceptions

CryptographicException

Thrown if the private key is invalid.

CreateFromValue(ReadOnlyMemory<byte>, KeyType)

Creates a new instance of ECPrivateKey from the given privateValue and keyType.

public static ECPrivateKey CreateFromValue(ReadOnlyMemory<byte> privateValue, KeyType keyType)

Parameters

privateValue ReadOnlyMemory<byte>

The raw private key data.

keyType KeyType

The type of key this is.

Returns

ECPrivateKey

A new instance of ECPrivateKey.

Remarks

The privateValue is taken as the raw private key data (scalar value).

Exceptions

ArgumentException

Thrown if the key type is not a valid EC key.

ExportPkcs8PrivateKey()

Exports the current key in the PKCS#8 PrivateKeyInfo format.

public override byte[] ExportPkcs8PrivateKey()

Returns

byte[]

A byte array containing the PKCS#8 PrivateKeyInfo representation of this key.