Show / Hide Table of Contents

SetEnabledNfcCapabilities Method

SetEnabledNfcCapabilities(YubiKeyCapabilities)

Sets which NFC features are enabled (and disabled).

C#
public void SetEnabledNfcCapabilities(YubiKeyCapabilities yubiKeyCapabilities)

Parameters

Type Name Description
YubiKeyCapabilities yubiKeyCapabilities

The desired set of NFC features to enable on the YubiKey. A set flag means that the related capability is enabled. Otherwise, the capability is disabled.

Implements

IYubiKeyDevice.SetEnabledNfcCapabilities(YubiKeyCapabilities)

Exceptions

Type Condition
InvalidOperationException

The command failed to complete.

NotSupportedException

An error occurred when attempting to connect to the device.

Remarks

Requires firmware version >= 5.0.0.

Modifies the value of EnabledNfcCapabilities. This requires the YubiKey's configuration to be unlocked (see ConfigurationLocked and UnlockConfiguration(ReadOnlySpan<byte>).

The YubiKey will reboot as part of this change. This will cause this IYubiKeyDevice object to become stale, and future connection attempts using this object are likely to fail. To get fresh IYubiKeys, use the YubiKey enumeration functions such as FindAll() and FindByTransport(Transport).

To see which NFC features are available on the YubiKey, see AvailableNfcCapabilities.

This example shows how to enable only the Piv capability over NFC on all YubiKeys where Piv is available. All other capabilities will be disabled. The new set of enabled NFC capabilities will be printed to the console, showing that only Piv is enabled over NFC.
IEnumerable<IYubiKeyDevice> yubiKeys =
    YubiKey.FindAll()
    .Where(d => d.AvailableNfcCapabilities.HasFlag(YubiKeyCapabilities.Piv));

foreach (IYubiKeyDevice yubiKey in yubiKeys) { device.SetEnabledNfcCapabilities(YubiKeyCapabilities.Piv); }

// The devices may need a little time to finish rebooting sleep(100);

// Get fresh IYubiKeys IEnumerable<IYubiKeyDevice> freshYubiKeys = YubiKey.FindAll() .Where(d => d.AvailableNfcCapabilities.HasFlag(YubiKeyCapabilities.Piv));

int i = 1; foreach (IYubiKeyDevice yubiKey in freshYubiKeys) { Console.PrintLine($"{i:} {yubiKey.SerialNumber} - {yubiKey.EnabledNfcCapabilities}"); }

To change the state of some capabilities without affecting the others, you can do something like the following:
IYubiKeyDevice yubiKey = YubiKey.FindAll().First();

YubiKeyCapabilities desiredNfcCapabilities = yubiKey.EnabledNfcCapabilities;

// Selectively enable Piv desiredNfcCapabilities |= YubiKeyCapabilities.Piv;

// Selectively disable Otp desiredNfcCapabilities &= ~YubiKeyCapabilities.Otp;

yubiKey.SetEnabledNfcCapabilities(desiredNfcCapabilities);

See Also

SetDeviceInfoCommand
In this article
Back to top Generated by DocFX