Skip to content

RsaJsonWebKeyExtensions Class

Converts between an RSA JSON Web Key and the platform's RSA types, and measures the key's modulus.

C#
public static class RsaJsonWebKeyExtensions

Inheritance System.Object → RsaJsonWebKeyExtensions

Methods

RsaJsonWebKeyExtensions.Apply(this RsaJsonWebKey, RSAParameters) Method

Applies RSA parameters to an RsaJsonWebKey.

C#
public static Abblix.Jwt.RsaJsonWebKey Apply(this Abblix.Jwt.RsaJsonWebKey jwk, System.Security.Cryptography.RSAParameters parameters);

Parameters

jwk RsaJsonWebKey

The RsaJsonWebKey to which the RSA parameters are to be applied.

parameters System.Security.Cryptography.RSAParameters

The RSAParameters providing the RSA key information.

Returns

RsaJsonWebKey
The updated RsaJsonWebKey with applied RSA parameters.

RsaJsonWebKeyExtensions.ModulusBitLength(this RsaJsonWebKey) Method

The real bit length of the key's modulus, ignoring any leading zero octets.

C#
public static int ModulusBitLength(this Abblix.Jwt.RsaJsonWebKey key);

Parameters

key RsaJsonWebKey

Returns

System.Int32

Remarks

RSA.KeySize is not this number, and how far it differs depends on the platform. It reports the key as the importer built it: Windows CNG keeps a left-padded modulus at its padded length and reports twice the real strength, while Linux (OpenSSL) strips the leading zeros and reports the true one. So a size check written against that property refuses a downgraded key on one operating system and admits it on another - which is a worse failure than either, because the deployment that admits it looks identical to the one that does not, and the forgery arrives later from whoever factored the real modulus.

Measuring the modulus itself removes the platform from the question. It is also never larger than RSA.KeySize, so switching to it can only add refusals, never remove one.

RFC 7518 Section 2 requires the minimal encoding - "The octet sequence MUST utilize the minimum number of octets needed to represent the value" - which is what this measurement follows. Padding far enough to matter is NOT something a library does by accident: the one benign quirk the specification records is a single extra zero octet (Section 6.3.1.1, "returning 257 octets for a 2048-bit key"), and one octet moves neither check in either direction. Sixty-four of them is a malformed or hostile JWKS entry.

The leading octet contributes only the bits from its own highest set bit down, which is what makes this the modulus's true length rather than a rounded-up octet count.

RsaJsonWebKeyExtensions.ToRsa(this RsaJsonWebKey) Method

Converts an RsaJsonWebKey to an RSA object, which represents an RSA public and private key pair or just a public key.

C#
public static System.Security.Cryptography.RSA ToRsa(this Abblix.Jwt.RsaJsonWebKey key);

Parameters

key RsaJsonWebKey

The RsaJsonWebKey to be converted.

Returns

System.Security.Cryptography.RSA
An RSA object based on the provided RsaJsonWebKey.

RsaJsonWebKeyExtensions.ToRsaParameters(this RsaJsonWebKey) Method

Converts an RsaJsonWebKey to RSAParameters, which represent the key parameters used in RSA cryptographic operations.

C#
public static System.Security.Cryptography.RSAParameters ToRsaParameters(this Abblix.Jwt.RsaJsonWebKey key);

Parameters

key RsaJsonWebKey

The RsaJsonWebKey to be converted.

Returns

System.Security.Cryptography.RSAParameters
An RSAParameters object based on the provided RsaJsonWebKey.