Class CoseEcPublicKey
A representation of an Elliptic Curve public key in COSE form.
public class CoseEcPublicKey : CoseKey
- Inheritance
-
objectCoseEcPublicKey
- Inherited Members
Remarks
An ECC public key consists of a curve and public point. In FIDO2, the curve is represented by the CoseAlgorithmIdentifier and the public point is simply an x-coordinate and a y-coordinate.
The FIDO2 standard also specifies an encoding of the public key information. It uses the representation defined in RFC8152: CBOR Object Signing and Encryption (COSE) standard. Supplementary information can be found in section 6.5.6 of the CTAP2.1 specification (under the heading `getPublicKey()`).
This class has multiple constructors. One constructs an empty object and allows the caller to set the key parameters via the properties on this class. Another constructs a key based on the COSE form encoded in CBOR. Lastly, there is a constructor that takes in a .NET representation of an EC public key used for interoperating with the .NET cryptographic library.
The YubiKey's FIDO2 application currently only supports the NIST P-256 curve. Thus, the SDK - as of version 1.5.0 - will also only support this curve.
Constructors
CoseEcPublicKey(ReadOnlyMemory<byte>)
Construct a CoseEcPublicKey based on the CBOR encoding
of a COSE_Key
.
public CoseEcPublicKey(ReadOnlyMemory<byte> encodedCoseKey)
Parameters
encodedCoseKey
ReadOnlyMemory<byte>The CBOR encoding.
Exceptions
- Ctap2DataException
The
encodedCoseKey
is not a correct EC Public Key encoding.
CoseEcPublicKey(ECParameters)
Construct a CoseEcPublicKey based on .NET elliptic curve parameters.
public CoseEcPublicKey(ECParameters ecParameters)
Parameters
ecParameters
ECParametersAn
ECParameters
structure with a specified Curve and a public point Q.
Exceptions
- ArgumentException
The
ECParameters
object does not contain a valid curve and- NotSupportedException
The parameters/public key specified is not supported.
CoseEcPublicKey(CoseEcCurve, ReadOnlyMemory<byte>, ReadOnlyMemory<byte>)
Construct a CoseEcPublicKey based on the curve and point.
public CoseEcPublicKey(CoseEcCurve curve, ReadOnlyMemory<byte> xCoordinate, ReadOnlyMemory<byte> yCoordinate)
Parameters
curve
CoseEcCurveThe curve for this public key.
xCoordinate
ReadOnlyMemory<byte>The x-coordinate of the public point.
yCoordinate
ReadOnlyMemory<byte>The y-coordinate of the public point.
Remarks
An ECC public key is a curve and public point (x and y coordinates). This constructor expects the length of each coordinate to be at least one byte and 32 bytes or fewer. Valid keys are P-256, P-384, and P-521. Note: Certain keys might not be supported by the YubiKey.
Exceptions
- ArgumentException
The xCoordinate or yCoordinate is not the correct length, or when the curve is not supported.
CoseEcPublicKey(CoseEcCurve, CoseAlgorithmIdentifier, ReadOnlyMemory<byte>, ReadOnlyMemory<byte>)
Construct a CoseEcPublicKey based on the curve and x and y coordinates.
public CoseEcPublicKey(CoseEcCurve curve, CoseAlgorithmIdentifier algorithm, ReadOnlyMemory<byte> xCoordinate, ReadOnlyMemory<byte> yCoordinate)
Parameters
curve
CoseEcCurveThe curve for this public key.
algorithm
CoseAlgorithmIdentifierThe algorithm of the key.
xCoordinate
ReadOnlyMemory<byte>The x-coordinate of the public point.
yCoordinate
ReadOnlyMemory<byte>The y-coordinate of the public point.
Remarks
An ECC public key is a curve and public point (x and y coordinates). Valid keys are P-256, P-384, and P-521. Note: Certain keys might not be supported by the YubiKey.
Exceptions
- ArgumentException
The xCoordinate or yCoordinate is not the correct length, or when the curve is not supported.
Properties
Curve
The Elliptic Curve that the key resides on.
public CoseEcCurve Curve { get; set; }
Property Value
Exceptions
- NotSupportedException
On set, the curve specified is not supported.
XCoordinate
The X-coordinate of the public point.
public ReadOnlyMemory<byte> XCoordinate { get; set; }
Property Value
- ReadOnlyMemory<byte>
Exceptions
- ArgumentException
On set, the coordinate in not the correct length.
YCoordinate
The Y-coordinate of the public point.
public ReadOnlyMemory<byte> YCoordinate { get; set; }
Property Value
- ReadOnlyMemory<byte>
Exceptions
- ArgumentException
On set, the coordinate in not the correct length.
Methods
CreateFromEncodedKey(ReadOnlyMemory<byte>)
Creates a new instance of CoseEcPublicKey from the given encoded COSE key.
public static CoseEcPublicKey CreateFromEncodedKey(ReadOnlyMemory<byte> encodedCoseKey)
Parameters
encodedCoseKey
ReadOnlyMemory<byte>The encoded COSE key in CBOR format.
Returns
- CoseEcPublicKey
A CoseEcPublicKey object initialized with the provided encoded key data.
Exceptions
- Ctap2DataException
Thrown if the
encodedCoseKey
is not a valid EC Public Key encoding.
Encode()
Return a new byte array that is the key data encoded following the FIDO2/CBOR standard.
public override byte[] Encode()
Returns
- byte[]
The encoded key.
Exceptions
- InvalidOperationException
The object contains no key data.
ToEcParameters()
Returns the COSE key as a new .NET ECParameters
structure. Used
for interoperating with the .NET crypto library.
public ECParameters ToEcParameters()
Returns
- ECParameters
The public key in the form of an
ECParameters
structure.