X500DistinguishedName.Decode Method (X500DistinguishedNameFlags)

 

Decodes a distinguished name using the characteristics specified by the flag parameter.

Namespace:   System.Security.Cryptography.X509Certificates
Assembly:  System (in System.dll)

public string Decode(
	X500DistinguishedNameFlags flag
)

Parameters

flag
Type: System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags

A bitwise combination of the enumeration values that specify the characteristics of the distinguished name.

Return Value

Type: System.String

The decoded distinguished name.

Exception Condition
CryptographicException

The certificate has an invalid name.

This method decodes the ASN encoded distinguished name into a string value.

The following code example shows how to use the X500DistinguishedName class.

using System;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;

class X500Sample
{
	static void Main()
	{
		try
		{
			X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
			store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
			X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
			X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
			X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Test Certificate Select", "Select a certificate from the following list to get information on that certificate", X509SelectionFlag.MultiSelection);
			Console.WriteLine("Number of certificates: {0}{1}", scollection.Count, Environment.NewLine);
			foreach (X509Certificate2 x509 in scollection)
			{
				X500DistinguishedName dname = new X500DistinguishedName(x509.SubjectName);
				Console.WriteLine("X500DistinguishedName: {0}{1}", dname.Name, Environment.NewLine);
				x509.Reset();
			}
			store.Close();
		}
		catch (CryptographicException)
		{
			Console.WriteLine("Information could not be written out for this certificate.");
		}

	}
}

.NET Framework
Available since 2.0
Return to top
Show: