Skip to main content

JsonWebKeyExtensions Class

Abblix.Jwt

Abblix.Jwt

JsonWebKeyExtensions Class

Provides extension methods for the JsonWebKey model to simplify the process of populating its properties from different sources. These methods enable easy conversion between JsonWebKey and various cryptographic representations.

public static class JsonWebKeyExtensions

Inheritance System.Object → JsonWebKeyExtensions

Methods

JsonWebKeyExtensions.Apply(this EllipticCurveJsonWebKey, ECParameters) Method

Applies Elliptic Curve parameters to an EllipticCurveJsonWebKey.

public static Abblix.Jwt.EllipticCurveJsonWebKey Apply(this Abblix.Jwt.EllipticCurveJsonWebKey jwk, System.Security.Cryptography.ECParameters parameters);

Parameters

jwk EllipticCurveJsonWebKey

The EllipticCurveJsonWebKey to which the EC parameters are to be applied.

parameters System.Security.Cryptography.ECParameters

The ECParameters providing the Elliptic Curve key information.

Returns

EllipticCurveJsonWebKey
The updated EllipticCurveJsonWebKey with applied Elliptic Curve parameters.

JsonWebKeyExtensions.Apply(this RsaJsonWebKey, RSAParameters) Method

Applies RSA parameters to an RsaJsonWebKey.

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.

JsonWebKeyExtensions.Apply<T>(this T, X509Certificate2) Method

Applies X509Certificate2 properties to a JsonWebKey.

public static T Apply<T>(this T jwk, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate)
where T : Abblix.Jwt.JsonWebKey;

Type parameters

T

The type of JsonWebKey (must be a subclass).

Parameters

jwk T

The JsonWebKey to which the certificate properties are to be applied.

certificate System.Security.Cryptography.X509Certificates.X509Certificate2

The X509Certificate2 providing the properties.

Returns

T
The updated JsonWebKey with applied certificate properties.

JsonWebKeyExtensions.ToEcdsa(this EllipticCurveJsonWebKey) Method

Converts an EllipticCurveJsonWebKey to an ECDsa object, which represents an ECDSA public and private key pair or just a public key.

public static System.Security.Cryptography.ECDsa ToEcdsa(this Abblix.Jwt.EllipticCurveJsonWebKey key);

Parameters

key EllipticCurveJsonWebKey

The EllipticCurveJsonWebKey to be converted.

Returns

System.Security.Cryptography.ECDsa
An ECDsa object based on the provided EllipticCurveJsonWebKey.

JsonWebKeyExtensions.ToEcParameters(this EllipticCurveJsonWebKey) Method

Converts an EllipticCurveJsonWebKey to ECParameters, which represent the key parameters used in ECDSA cryptographic operations. Supports P-256, P-384, and P-521 curves as defined in NIST standards.

public static System.Security.Cryptography.ECParameters ToEcParameters(this Abblix.Jwt.EllipticCurveJsonWebKey key);

Parameters

key EllipticCurveJsonWebKey

The EllipticCurveJsonWebKey to be converted.

Returns

System.Security.Cryptography.ECParameters
An ECParameters object based on the provided EllipticCurveJsonWebKey.

Exceptions

System.InvalidOperationException
Thrown when the curve type is not supported.

JsonWebKeyExtensions.ToJsonWebKey(this X509Certificate2, bool) Method

Converts an X509Certificate2 to a JsonWebKey. The private keys can be optionally included in the conversion.

public static Abblix.Jwt.JsonWebKey ToJsonWebKey(this System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool includePrivateKeys=false);

Parameters

certificate System.Security.Cryptography.X509Certificates.X509Certificate2

The X509Certificate2 to convert.

includePrivateKeys System.Boolean

Indicates whether to include private keys in the conversion.

Returns

JsonWebKey
A JsonWebKey representing the certificate.

JsonWebKeyExtensions.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.

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.

JsonWebKeyExtensions.ToRsaParameters(this RsaJsonWebKey) Method

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

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.