GetDataCommand Class
Namespace: Yubico.YubiKey.Piv.Commands Assembly: Yubico.YubiKey.dllGet a Data Object from the YubiKey.
public sealed class GetDataCommand : Object, IYubiKeyCommand<GetDataResponse>
Implements
Remarks
The partner Response class is GetDataResponse.
See also the User's Manual entries on Get and Put Data and PIV objects, along with the documentation for the PutDataCommand.
Note that for some Data Objects there are higher-level APIs that are easier to use. An application that needs to retrieve information often will not need to use this command. For example, if you want to get a certificate from a YubiKey, use GetCertificate(Byte). Or if you want to store/retrieve Key History, use ReadObject<T>() and WriteObject(PivDataObject) along with the KeyHistory class. Under the covers, these APIs will ultimately call this command. But the application that uses the SDK can simply make the specific API calls, rather than use Get Data.
There are a number of ways to use this command. The old, obsolete way is
to provide the DataTag using the PivDataTag
enum. The constructor
GetDataCommand(PivDataTag)
and the property Tag
require
using PIV-defined DataTags. This constructor and that property are marked
"Obsolete" and will be removed from the SDK in the future. However, it
will still be possible to get the same functionality using the updated
API.
The API you should use are the constructors GetDataCommand()
, and
GetDataCommand(int)
, along with the property DataTag
. Using
these will allow you to use any DataTag (not just those defined by PIV).
While you can retrieve any data under a PIV-defined DataTag, if you want to
use only PIV-defined DataTags, you can use the PivDataTag
class.
For example,
// Retrieve IrisImages
var getCmd = new GetDataCommand((int)PivDataTag.IrisImages);
GetDataResponse getRsp = connection.SendCommand(getCmd);
ReadOnlyMemory<byte> encodedData = getRsp.GetData();
if (!PivDataTag.IrisImages.IsValidEncodingForPut(encodedData))
{
// handle error case.
}
Note that when you set an object with the DataTag using either the old constructor/property or the new versions, when you get it (using either old or new), you are getting the same thing. For example,
// Use the old, obsolete API to set the tag.
var getCmd = new GetDataCommand()
{
Tag = PivDataTag.KeyHistory,
}
PivDataTag pivDataTag = getCmd.Tag;
int dataTag = getCmd.DataTag;
// At this point pivDataTag will equal PivDataTag.KeyHistory = 0x005FC10C
// dataTag will equal 0x005FC10C
// Even though the code used the old API to set the Tag property
// the new API DataTag property will return the same value.
The data returned will begin with the tag 0x53
. For example,
Suppose the data is
04 02 55 44 02 01 7F
It will be returned by the GetDataCommand as
53 07
04 02 55 44 02 01 7F
Example:
IYubiKeyConnection connection = key.Connect(YubiKeyApplication.Piv);
GetDataCommand getDataCommand = new GetDataCommand((int)PivDataTag.Chuid);
GetDataResponse getDataResponse = connection.SendCommand(getDataCommand);
if (getDataResponse.StatusWord == SWConstants.Success)
{
ReadOnlyMemory<byte> getChuid = getDataResponse.GetData();
}
Constructors
Name | Description |
---|---|
GetDataCommand() | Initializes a new instance of the GetDataCommand class. |
GetDataCommand(Int32) | Initializes a new instance of the |
GetDataCommand(PivDataTag) | WarningThis constructor is obsolete, use Initializes a new instance of the |
Properties
Name | Description |
---|---|
Application | Gets the YubiKeyApplication to which this command belongs. For this command it's PIV. |
DataTag | The tag specifying from where the data is to be retrieved. |
Tag | WarningThis property is obsolete, use The tag specifying which data to get. |
Methods
Name | Description |
---|---|
CreateCommandApdu() | Creates a well-formed CommandApdu to send to the YubiKey. |
CreateResponseForApdu(ResponseApdu) | Creates the corresponding IYubiKeyResponse implementation for the current command. |