public static RSA ResolveRsa(this SigningCredentials credentials, bool throwIfError = true) { credentials.NotNull(nameof(credentials)); if (credentials.Key is X509SecurityKey x509Key) { return(x509Key.PrivateKey as RSA); } if (credentials.Key is RsaSecurityKey rsaKey) { if (rsaKey.Rsa.IsNull()) { var rsa = RSA.Create(); rsa.ImportParameters(rsaKey.Parameters); return(rsa); } return(rsaKey.Rsa); } if (throwIfError) { throw new NotSupportedException(InternalResource.NotSupportedExceptionSecurityKey); } return(null); }
public static X509Certificate2 ResolveCertificate(this SigningCredentials credentials, bool throwIfError = true) { credentials.NotNull(nameof(credentials)); if (credentials.Key is X509SecurityKey x509Key) { return(x509Key.Certificate); } if (throwIfError) { throw new NotSupportedException(InternalResource.NotSupportedExceptionSecurityKey); } return(null); }