Import a certificate into the given slot.
public void ImportCertificate(byte slotNumber, X509Certificate2 certificate)
The slot into which the key will be imported.
The certificate to import into the YubiKey.
The slot specified is not valid for importing a certificate.
There is no
The user canceled management key collection.
Mutual authentication was performed and the YubiKey was not authenticated.
When you import a certificate, you specify which slot will hold this cert. If there is a cert in that slot already, this method will replace it.
The PIV standard specifies that the maximum length of a cert is 1,856 bytes. The YubiKey allows for certs up to 3,052 bytes. However, if you want your application to be PIV-compliant, then use certs no longer than 1,856 bytes.
This method will not verify that the cert matches the private key in the slot. It will simply store the cert given in the slot specified.
In order to perform this operation, the management key must be
authenticated during this session. If it has not been authenticated,
this method will call AuthenticateManagementKey(Boolean). That
is, your application does not need to authenticate the management key
separately (i.e., call
AuthenticateManagementKey), this method will determine if the
management key has been authenticated or not, and if not, it will
make the call to perform mutual authentication.
The authentication method will collect the management key using the
KeyCollector delegate. If no such delegate has been set, it
will throw an exception.
KeyCollector has an option to cancel the operation. That
AuthenticateManagementKey method will call the
KeyCollector requesting the management key, and it is possible
that during the collection operations, the user cancels. The
KeyCollector will return to the authentication method noting
the cancellation. In that case, it will throw an exception. If you
want the authentication to return
false on user cancellation,
you must call TryAuthenticateManagementKey(Boolean) directly
before calling this method.