Прочетете на английски Редактиране

Споделяне чрез


X509CertificateValidator Class

Definition

Validates an X.509 certificate.

C#
public abstract class X509CertificateValidator
C#
public abstract class X509CertificateValidator : System.IdentityModel.Configuration.ICustomIdentityConfiguration
Inheritance
X509CertificateValidator
Derived
Implements

Examples

C#
public class MyX509CertificateValidator : X509CertificateValidator
{
    string allowedIssuerName;
    public MyX509CertificateValidator(string allowedIssuerName)
    {
        if (allowedIssuerName == null)
        {
            throw new ArgumentNullException("allowedIssuerName");
        }

        this.allowedIssuerName = allowedIssuerName;
    }
    public override void Validate(X509Certificate2 certificate)
    {
        // Check that there is a certificate.
        if (certificate == null)
        {
            throw new ArgumentNullException("certificate");
        }

        // Check that the certificate issuer matches the configured issuer
        if (allowedIssuerName != certificate.IssuerName.Name)
        {
            throw new SecurityTokenValidationException
              ("Certificate was not issued by a trusted issuer");
        }
    }
}

Remarks

Use the X509CertificateValidator class to specify how an X.509 certificate is deemed valid. This can be done using by deriving a class from X509CertificateValidator and overriding the Validate method.

Constructors

X509CertificateValidator()

Initializes a new instance of the X509CertificateValidator class.

Properties

ChainTrust

Gets a validator that validates the X.509 certificate using a trust chain.

None

Gets a validator that performs no validation on an X.509 certificate. As a result, an X.509 certificate is always considered to be valid.

PeerOrChainTrust

Gets a validator that verifies the certificate is in the TrustedPeople certificate store or by building a certificate trust chain. The certificate is trusted if it passes either verification method.

PeerTrust

Gets a validator that verifies the certificate is in the TrustedPeople certificate store.

Methods

CreateChainTrustValidator(Boolean, X509ChainPolicy)

Gets a validator that verifies the X.509 certificate by specifying the context and chain policy that is used to build and verify a trust chain.

CreatePeerOrChainTrustValidator(Boolean, X509ChainPolicy)

Gets a validator that verifies the certificate is in the TrustedPeople certificate store or by specifying the context and chain policy that is used to build a certificate trust chain. The certificate is trusted if it passes either verification method.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
LoadCustomConfiguration(XmlNodeList)

When overridden in a derived class, loads custom configuration from XML.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
Validate(X509Certificate2)

When overridden in a derived class, validates the X.509 certificate.

Applies to

Продукт Версии
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)