Loe inglise keeles Redigeeri

Jagamisviis:


X509BasicConstraintsExtension Constructors

Definition

Initializes a new instance of the X509BasicConstraintsExtension class.

Overloads

X509BasicConstraintsExtension()

Initializes a new instance of the X509BasicConstraintsExtension class.

X509BasicConstraintsExtension(AsnEncodedData, Boolean)

Initializes a new instance of the X509BasicConstraintsExtension class using an AsnEncodedData object and a value that identifies whether the extension is critical.

X509BasicConstraintsExtension(Boolean, Boolean, Int32, Boolean)

Initializes a new instance of the X509BasicConstraintsExtension class. Parameters specify a value that indicates whether a certificate is a certificate authority (CA) certificate, a value that indicates whether the certificate has a restriction on the number of path levels it allows, the number of levels allowed in a certificate's path, and a value that indicates whether the extension is critical.

X509BasicConstraintsExtension()

Source:
X509BasicConstraintsExtension.cs
Source:
X509BasicConstraintsExtension.cs
Source:
X509BasicConstraintsExtension.cs

Initializes a new instance of the X509BasicConstraintsExtension class.

public X509BasicConstraintsExtension ();

Examples

The following code example demonstrates how to open a user's personal certificate store and display information about each certificate in the store. This example uses the X509BasicConstraintsExtension class to display the information.

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

public class CertSelect
{
    public static void Main()
    {
        try
        {
            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            for (int i = 0; i < collection.Count; i++)
            {
                foreach (X509Extension extension in collection[i].Extensions)
                {
                    Console.WriteLine(extension.Oid.FriendlyName + "(" + extension.Oid.Value + ")");

                    if (extension.Oid.FriendlyName == "Key Usage")
                    {
                        X509KeyUsageExtension ext = (X509KeyUsageExtension)extension;
                        Console.WriteLine(ext.KeyUsages);
                    }

                    if (extension.Oid.FriendlyName == "Basic Constraints")
                    {
                        X509BasicConstraintsExtension ext = (X509BasicConstraintsExtension)extension;
                        Console.WriteLine(ext.CertificateAuthority);
                        Console.WriteLine(ext.HasPathLengthConstraint);
                        Console.WriteLine(ext.PathLengthConstraint);
                    }

                    if (extension.Oid.FriendlyName == "Subject Key Identifier")
                    {
                        X509SubjectKeyIdentifierExtension ext = (X509SubjectKeyIdentifierExtension)extension;
                        Console.WriteLine(ext.SubjectKeyIdentifier);
                    }

                    if (extension.Oid.FriendlyName == "Enhanced Key Usage")
                    {
                        X509EnhancedKeyUsageExtension ext = (X509EnhancedKeyUsageExtension)extension;
                        OidCollection oids = ext.EnhancedKeyUsages;
                        foreach (Oid oid in oids)
                        {
                            Console.WriteLine(oid.FriendlyName + "(" + oid.Value + ")");
                        }
                    }
                }
            }
            store.Close();
        }
        catch (CryptographicException)
        {
            Console.WriteLine("Information could not be written out for this certificate.");
        }
    }
}

Applies to

.NET 9 ja muud versioonid
Toode Versioonid
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

X509BasicConstraintsExtension(AsnEncodedData, Boolean)

Source:
X509BasicConstraintsExtension.cs
Source:
X509BasicConstraintsExtension.cs
Source:
X509BasicConstraintsExtension.cs

Initializes a new instance of the X509BasicConstraintsExtension class using an AsnEncodedData object and a value that identifies whether the extension is critical.

public X509BasicConstraintsExtension (System.Security.Cryptography.AsnEncodedData encodedBasicConstraints, bool critical);

Parameters

encodedBasicConstraints
AsnEncodedData

The encoded data to use to create the extension.

critical
Boolean

true if the extension is critical; otherwise, false.

Remarks

Use this constructor if the information to create an extension is already in an AsnEncodedData object.

Applies to

.NET 9 ja muud versioonid
Toode Versioonid
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

X509BasicConstraintsExtension(Boolean, Boolean, Int32, Boolean)

Source:
X509BasicConstraintsExtension.cs
Source:
X509BasicConstraintsExtension.cs
Source:
X509BasicConstraintsExtension.cs

Initializes a new instance of the X509BasicConstraintsExtension class. Parameters specify a value that indicates whether a certificate is a certificate authority (CA) certificate, a value that indicates whether the certificate has a restriction on the number of path levels it allows, the number of levels allowed in a certificate's path, and a value that indicates whether the extension is critical.

public X509BasicConstraintsExtension (bool certificateAuthority, bool hasPathLengthConstraint, int pathLengthConstraint, bool critical);

Parameters

certificateAuthority
Boolean

true if the certificate is a certificate authority (CA) certificate; otherwise, false.

hasPathLengthConstraint
Boolean

true if the certificate has a restriction on the number of path levels it allows; otherwise, false.

pathLengthConstraint
Int32

The number of levels allowed in a certificate's path.

critical
Boolean

true if the extension is critical; otherwise, false.

Applies to

.NET 9 ja muud versioonid
Toode Versioonid
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1