<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.21.0" />

Microsoft.IdentityModel.Tokens.JsonWebKeyConverter

public class JsonWebKeyConverter
Converts a SecurityKey into a JsonWebKey Supports: converting to a JsonWebKey from one of: RsaSecurityKey, X509SecurityKey, and SymmetricSecurityKey.

Converts an MlDsaSecurityKey into a JsonWebKey.

Converts a RsaSecurityKey into a JsonWebKey

Converts a SecurityKey into a JsonWebKey

Converts a SymmetricSecurityKey into a JsonWebKey

Converts a X509SecurityKey into a JsonWebKey

public static JsonWebKey ConvertFromX509SecurityKey(X509SecurityKey key, bool representAsRsaKey)

Converts a X509SecurityKey into a JsonWebKey.

public static bool TryConvertToSecurityKey(JsonWebKey webKey, out SecurityKey key)

This will attempt to convert the JsonWebKey to a SecurityKey.