Show / Hide Table of Contents

GetCertificate Method

GetCertificate(byte)

Get the certificate in the given slot.

C#
public X509Certificate2 GetCertificate(byte slotNumber)

Parameters

Type Name Description
byte slotNumber

The slot containing the requested cert.

Returns

X509Certificate2

The cert residing in the slot specified.

Exceptions

Type Condition
ArgumentException

The slot specified is not valid for getting a certificate.

InvalidOperationException

The slot did not contain a cert, or the YubiKey had some other error, such as unreliable connection.

Remarks

After obtaining a cert, you can install it into the slot containing the associated private key (ImportCertificate(byte, X509Certificate2)). Later on, when you need the cert (e.g. to send it along with a signed message), call this method to retrieve it.

It is not necessary to authenticate the management key nor verify the PIN in order to obtain a certificate.

If the slotNumber given is for a slot that does not hold asymmetric keys, or if there is no cert in the slot, this method will throw an exception.

If you want to get the attestation cert, do not use this method, call GetAttestationCertificate(). If you call this method with slot number 0xF9 (PivSlot.Attestation) it will throw an exception.

In this article
Back to top Generated by DocFX