Class GetPublicKeyCommand
- Namespace
- Yubico.YubiKey.YubiHsmAuth.Commands
- Assembly
- Yubico.YubiKey.dll
The command class for retrieving the public key from an asymmetric credential in the YubiHSM Auth application.
public sealed class GetPublicKeyCommand : IYubiKeyCommand<GetPublicKeyResponse>
- Inheritance
-
objectGetPublicKeyCommand
- Implements
Remarks
This command retrieves the public key (PK-OCE) from an asymmetric credential. This public key is typically used in asymmetric authentication protocols such as ECC P-256.
The partner response class is GetPublicKeyResponse.
Constructors
GetPublicKeyCommand(string)
Retrieve the public key from an asymmetric credential.
public GetPublicKeyCommand(string credentialLabel)
Parameters
credentialLabelstringThe label of the credential for which to retrieve the public key. The string must meet the same requirements as Label.
Remarks
This command retrieves the public key (PK-OCE) from the specified asymmetric credential. The returned key is a 65-byte uncompressed elliptic curve point (for ECC P-256 credentials).
Properties
Application
Gets the YubiKeyApplication (e.g. PIV, OATH, etc.) to which this command applies.
public YubiKeyApplication Application { get; }
Property Value
- YubiKeyApplication
YubiKeyApplication.Otp, YubiKeyApplication.Piv, etc.
CredentialLabel
A short name or description of the Credential.
public string CredentialLabel { get; set; }
Property Value
- string
Remarks
The string only contains characters that can be encoded with UTF-8, and its UTF-8 byte count is between MinLabelByteCount and MaxLabelByteCount. Non-printing characters are allowed, as long as they can be encoded with UTF-8. For example, null (UTF-8: 0x00) and Right-To-Left Mark U+200F (UTF-8: 0xE2 0x80 0x8F) would be acceptable.
The System.Text.UTF8Encoding class contains methods such as System.Text.UTF8Encoding.GetByteCount(string) which can be used to validate the string prior to attempting to set it here. It is recommended to use the constructor System.Text.UTF8Encoding.UTF8Encoding(bool, bool) so error detection is enabled for invalid characters.
Exceptions
- ArgumentNullException
Thrown when the supplied string is null.
- ArgumentOutOfRangeException
Thrown when the string's UTF-8 byte count does not meet the length parameters MinLabelByteCount and MaxLabelByteCount.
- ArgumentException
Thrown when there is a character that cannot be encoded with UTF-8. The exact exception may be derived from ArgumentException.
Methods
CreateCommandApdu()
Creates a well-formed CommandApdu to send to the YubiKey.
public CommandApdu CreateCommandApdu()
Returns
- CommandApdu
A valid CommandApdu that is ready to be sent to the YubiKey, or passed along to additional encoders for further processing.
Remarks
This method will first perform validation on all of the parameters and data provided to it. The CommandAPDU it creates should contain all of the data payload for the command, even if it exceeds 65,535 bytes as specified by the ISO 7816-4 specification. The APDU will be properly chained by the device connection prior to being sent to the YubiKey, and the responses will collapsed into a single result.
CreateResponseForApdu(ResponseApdu)
Creates the corresponding IYubiKeyResponse implementation for the current command.
public GetPublicKeyResponse CreateResponseForApdu(ResponseApdu responseApdu)
Parameters
responseApduResponseApduThe ResponseApdu returned by the YubiKey.
Returns
- GetPublicKeyResponse
The implementation of IYubiKeyResponse that parses and presents ths response APDU.