Show / Hide Table of Contents

TrySetPin Method

TrySetPin()

Tries to set the initial FIDO2 PIN using the KeyCollector. To change an existing PIN, use the TryChangePin() function.

C#
public bool TrySetPin()

Returns

bool

True on success, False if the user cancelled PIN collection, and an exception for all other kinds of failures.

Exceptions

Type Condition
SecurityException

The YubiKey already has a PIN set. This function cannot be used to change the PIN.

Remarks

The Yubikey is manufactured with no default PIN set on the FIDO2 application. To initially configure a PIN, use this function. This function will only succeed if no PIN is currently configured. To change an already set PIN, use the ChangePin() method instead. Once set, a PIN cannot be removed without resetting the FIDO2 application. This operation will unset the PIN as well as clear all registered credentials.

Several considerations must be made when collecting the PIN.

  • It must be encoded in UTF-8 with Normalization Form C.
  • It must be at least 4 Unicode code points in length.
  • It must not exceed 63 bytes in encoded length.
Read more about PINs here.

TrySetPin(ReadOnlyMemory<byte>)

Tries to set the initial FIDO2 PIN. To change an existing PIN, use the TryChangePin() function.

C#
public bool TrySetPin(ReadOnlyMemory<byte> newPin)

Parameters

Type Name Description
ReadOnlyMemory<byte> newPin

The PIN to program onto the YubiKey. It must be encoded in UTF-8 with Normalization Form C. It must be at least 4 Unicode code points in length, and not to exceed 63 bytes in encoded length. Read more about PINs here.

Returns

bool

True on success, False if the YubiKey has a PIN already set, and an exception for all other kinds of failures.

Remarks

The Yubikey is manufactured with no default PIN set on the FIDO2 application. To initially configure a PIN, use this function. This function will only succeed if no PIN is currently configured. To change an already set PIN, use the ChangePin() method instead. Once set, a PIN cannot be removed without resetting the FIDO2 application. This operation will unset the PIN as well as clear all registered credentials.

In this article
Back to top Generated by DocFX