The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
X509EnhancedKeyUsageExtension Class
.NET Framework 3.0
Defines the collection of object identifiers (OIDs) that indicates the applications that use the key. This class cannot be inherited.
Namespace: System.Security.Cryptography.X509Certificates
Assembly: System (in system.dll)
Assembly: System (in system.dll)
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 X509EnhancedKeyUsageExtension 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."); } } }
System.Object
System.Security.Cryptography.AsnEncodedData
System.Security.Cryptography.X509Certificates.X509Extension
System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension
System.Security.Cryptography.AsnEncodedData
System.Security.Cryptography.X509Certificates.X509Extension
System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
Show: