#### [Abblix\.Jwt](https://www.abblix.com/docs/api/abblix-jwt 'index')
### [Abblix\.Jwt](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt 'Abblix\.Jwt')

## RsaJsonWebKeyExtensions Class

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

```csharp
public static class RsaJsonWebKeyExtensions
```

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → RsaJsonWebKeyExtensions
### Methods

## RsaJsonWebKeyExtensions\.Apply\(this RsaJsonWebKey, RSAParameters\) Method {#Abblix.Jwt.RsaJsonWebKeyExtensions.Apply(thisAbblix.Jwt.RsaJsonWebKey,System.Security.Cryptography.RSAParameters)}

Applies RSA parameters to an RsaJsonWebKey\.

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

###### `jwk` [RsaJsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.RsaJsonWebKey 'Abblix\.Jwt\.RsaJsonWebKey') {#Abblix.Jwt.RsaJsonWebKeyExtensions.Apply(thisAbblix.Jwt.RsaJsonWebKey,System.Security.Cryptography.RSAParameters).jwk}

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

###### `parameters` [System\.Security\.Cryptography\.RSAParameters](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsaparameters 'System\.Security\.Cryptography\.RSAParameters') {#Abblix.Jwt.RsaJsonWebKeyExtensions.Apply(thisAbblix.Jwt.RsaJsonWebKey,System.Security.Cryptography.RSAParameters).parameters}

The RSAParameters providing the RSA key information\.

#### Returns
[RsaJsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.RsaJsonWebKey 'Abblix\.Jwt\.RsaJsonWebKey')  
The updated RsaJsonWebKey with applied RSA parameters\.

## RsaJsonWebKeyExtensions\.ModulusBitLength\(this RsaJsonWebKey\) Method {#Abblix.Jwt.RsaJsonWebKeyExtensions.ModulusBitLength(thisAbblix.Jwt.RsaJsonWebKey)}

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

```csharp
public static int ModulusBitLength(this Abblix.Jwt.RsaJsonWebKey key);
```
#### Parameters

###### `key` [RsaJsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.RsaJsonWebKey 'Abblix\.Jwt\.RsaJsonWebKey') {#Abblix.Jwt.RsaJsonWebKeyExtensions.ModulusBitLength(thisAbblix.Jwt.RsaJsonWebKey).key}

#### Returns
[System\.Int32](https://learn.microsoft.com/en-us/dotnet/api/system.int32 '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 {#Abblix.Jwt.RsaJsonWebKeyExtensions.ToRsa(thisAbblix.Jwt.RsaJsonWebKey)}

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

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

###### `key` [RsaJsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.RsaJsonWebKey 'Abblix\.Jwt\.RsaJsonWebKey') {#Abblix.Jwt.RsaJsonWebKeyExtensions.ToRsa(thisAbblix.Jwt.RsaJsonWebKey).key}

The RsaJsonWebKey to be converted\.

#### Returns
[System\.Security\.Cryptography\.RSA](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsa 'System\.Security\.Cryptography\.RSA')  
An RSA object based on the provided RsaJsonWebKey\.

## RsaJsonWebKeyExtensions\.ToRsaParameters\(this RsaJsonWebKey\) Method {#Abblix.Jwt.RsaJsonWebKeyExtensions.ToRsaParameters(thisAbblix.Jwt.RsaJsonWebKey)}

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

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

###### `key` [RsaJsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.RsaJsonWebKey 'Abblix\.Jwt\.RsaJsonWebKey') {#Abblix.Jwt.RsaJsonWebKeyExtensions.ToRsaParameters(thisAbblix.Jwt.RsaJsonWebKey).key}

The RsaJsonWebKey to be converted\.

#### Returns
[System\.Security\.Cryptography\.RSAParameters](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsaparameters 'System\.Security\.Cryptography\.RSAParameters')  
An RSAParameters object based on the provided RsaJsonWebKey\.
