Show / Hide Table of Contents

PivRsaPublicKey Class

Namespace: Yubico.YubiKey.Piv Assembly: Yubico.YubiKey.dll

This class holds an RSA public key.

C#
public sealed class PivRsaPublicKey : PivPublicKey
Inheritance object PivPublicKey PivRsaPublicKey

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 1024-bit, 2048-bit, 3072-bit, and 4096-bit RSA keys, which means that the modulus must be exactly 128, 256, 384, or 512 bytes long, respectively.

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.

In this article
Back to top Generated by DocFX