PivRsaPublicKey Class
Namespace: Yubico.YubiKey.Piv Assembly: Yubico.YubiKey.dllThis class holds an RSA public key.
public sealed class PivRsaPublicKey : PivPublicKey
Remarks
An RSA public key consists of a modulus and public exponent. To build an RSA key object from the modulus and public exponent, use this class's constructor.
Once you have the object built, you can get the encoded public key from
either the PivEncodedPublicKey
or YubiKeyEncodedPublicKey
property.
If you have an encoded public key, and want to build an object, use
the static factory Create
method in the base class
PivPublicKey.
The YubiKey supports only 1024-bit and 2048-bit RSA keys, which means that the modulus must be exactly 128 or 256 byte long.
The YubiKey supports only F4 (0x010001 = decimal 65,537) as the public
exponent. Note that if you have the public exponent as an int, you can
convert it to a byte array by using BinaryPrimitives
.
var exponentAsArray = new byte[4];
BinaryPrimitives.WriteInt32BigEndian(exponentAsArray, exponentAsInt);
Unlike the modulus, leading 00 bytes in the public exponent are ignored.
If you want to examine the public exponent as an int, you can either
know that if the class exists, the input was F4 (0x00010001
), or
use the BinaryPrimitives.ReadInt32BigEndian
method.
You can build an object from either the encoded public key (using the
PivPublicKey.Create
static factory method), and then examine the
modulus and public exponent, or you can build an object from the modulus
and public exponent, then examine the encoding.
Constructors
Name | Description |
---|---|
PivRsaPublicKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) | Create a new instance of an RSA public key object based on the given modulus and public exponent. |
Properties
Name | Description |
---|---|
Modulus | Contains the modulus portion of the RSA public key. |
PublicExponent | Contains the public exponent portion of the RSA public key. |