X509Certificate2.IssuerName Property

Gets the issuer name of the X.509 certificate.

public string IssuerName { get; }

Remarks

The IssuerName property returns a string representing the issuer of the certificate. This string is typically in a Distinguished Name (DN) format, such as "CN=My Certificate Authority, OU=IT, O=My Company, C=US".

If the certificate is self-signed, the IssuerName will be the same as the SubjectName property.

This property is useful for verifying the identity of the certificate issuer.

Example

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

public class CertificateIssuerExample
{
    public static void Main(string[] args)
    {
        try
        {
            // In a real application, you would load a certificate from a store or file.
            // For demonstration, let's assume we have a certificate object.
            // Example: X509Certificate2 cert = GetCertificateFromStore();

            // Placeholder for a certificate (replace with actual certificate loading)
            // This is a dummy certificate and might not have a valid issuer.
            // For a real scenario, you would use X509Certificate2(byte[] rawData) or X509Certificate2(string fileName)
            // or X509Certificate2 cert = store.Certificates[0];
            X509Certificate2 cert = new X509Certificate2();
            
            // If you don't have a real certificate, this example might show empty or default values.
            // To test effectively, use a certificate from your system.

            if (cert != null)
            {
                Console.WriteLine($"Certificate Subject: {cert.SubjectName.Name}");
                Console.WriteLine($"Certificate Issuer: {cert.IssuerName.Name}");

                // You can also access the issuer's Name property directly
                // Console.WriteLine($"Certificate Issuer (Name property): {cert.IssuerName.Name}");
            }
            else
            {
                Console.WriteLine("No certificate found or loaded.");
            }
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine($"Cryptographic error: {ex.Message}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An unexpected error occurred: {ex.Message}");
        }
    }

    // Placeholder for a method to retrieve a certificate from a store
    // public static X509Certificate2 GetCertificateFromStore()
    // {
    //     X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    //     store.Open(OpenFlags.ReadOnly);
    //     X509Certificate2Collection certCollection = store.Certificates;
    //     if (certCollection.Count > 0)
    //     {
    //         return certCollection[0];
    //     }
    //     store.Close();
    //     return null;
    // }
}

Requirements

See Also

System.Net.Security Namespace
X509Certificate2 Class
X509Certificate2.SubjectName Property