ReadNdefTag Method
ReadNdefTag()
Reads the OTP programmed in the short-press slot using the NFC Data-Exchange Format (NDEF) tag from NFC enabled YubiKeys. (Requires the YubiKey be connected via NFC).
public NdefDataReader ReadNdefTag()
Returns
An NdefDataReader instance that can interpret the NDEF data in the form that best suits your needs.
Implements
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when this method is called on a YubiKey that is not connected via NFC. |
System.InvalidOperationException | Thrown when the YubiKey could not select the NDEF file ID. |
Remarks
YubiKeys like the NEO and the 5-NFC series supports Near-Field Communication (NFC). NFC is a method in which the YubiKey can draw power from and communicate with another device over very short distances. This device can be a mobile phone, or a dedicated NFC smart card reader. The distances in which the YubiKey can operate depend on the signal strength provided by the reader, but is typically 1-3 centimeters.
For most YubiKey operations, the behavior will be the same over NFC as would be seen over USB. One significant difference, however, is reading content out of the "touch-enabled" configuration slots that the OTP application is built around. Devices like a smart phone will often automatically read the contents out of an NDEF tag. This allows the YubiKey to emulate the touch experience over NFC, at least when smart phones are involved.
Typically, desktop NFC readers do not automatically read NDEF tag contents. Therefore, a mechanism to programmatically read NDEF tags is required to achieve full feature parity with USB and NFC enabled smart phones. This method allows you to read the contents of an NDEF tag. Since the NDEF "slot" can contain either a URI or a text blob, an NdefDataReader instance is returned. This class allows you to read the NDEF data and interpret in a form that is the most appropriate for your application's needs.
Note: This method modifies the underlying connection to the YubiKey that the session uses. If an exception is thrown from this method, it is not guaranteed that the session will still be connected to the YubiKey. In that case, a new session will need to be established.