2using System.Collections.Generic;
 
    3using System.Diagnostics.Metrics;
 
    5using System.Security.AccessControl;
 
    6using System.Security.Cryptography.X509Certificates;
 
    8using System.Threading.Tasks;
 
   27        public string? 
Email { 
get; 
set; }
 
   47        public string? 
State { 
get; 
set; }
 
   57        public Dictionary<string, string> 
Unknown { 
get; } = [];
 
   67            var commonName = certificate.GetNameInfo(X509NameType.SimpleName, 
false);
 
   68            if (
string.IsNullOrEmpty(commonName))
 
   70                commonName = certificate.GetNameInfo(X509NameType.DnsName, 
false);
 
   73            if (!
string.IsNullOrEmpty(commonName))
 
   78            var email = certificate.GetNameInfo(X509NameType.EmailName, 
false);
 
   79            if (!
string.IsNullOrEmpty(email))
 
 
   93            Ensure.String.IsNotNullOrEmpty(subject, nameof(subject));
 
   95            var parts = subject.Split([
","], StringSplitOptions.RemoveEmptyEntries);
 
   97            foreach (var part 
in parts)
 
   99                int index = part.IndexOf(
'=');
 
  100                if (index <= 0 || index >= part.Length - 1)
 
  103                string key = part.Substring(0, index).Trim();
 
  104                string value = part.Substring(index + 1).Trim();
 
  107                switch (key.ToUpperInvariant())
 
  132                        Unknown[key.ToUpperInvariant()] = value; 
 
 
  154        public CertificateSubject(
string commonName, 
string? email, 
string? organization, 
string? organizationalUnit, 
string? locality, 
string? state, 
string? country)
 
  156            Ensure.String.IsNotNullOrEmpty(commonName, nameof(commonName));
 
 
  176            var components = 
new List<string>
 
  181            if (!
string.IsNullOrEmpty(
Email))
 
  183                components.Add($
"E={Email}");
 
  188                components.Add($
"O={Organization}");
 
  193                components.Add($
"OU={OrganizationalUnit}");
 
  196            if (!
string.IsNullOrEmpty(
Locality))
 
  198                components.Add($
"L={Locality}");
 
  201            if (!
string.IsNullOrEmpty(
State))
 
  203                components.Add($
"ST={State}");
 
  206            if (!
string.IsNullOrEmpty(
Country))
 
  208                components.Add($
"C={Country}");
 
  211            return string.Join(
", ", components);
 
 
 
Represents the subject of a certificate.
string? Email
Gets or sets the email address (E) of the certificate subject.
Dictionary< string, string > Unknown
Gets a dictionary of unknown keys and their values from the parsed subject string.
CertificateSubject(string subject)
Initializes a new instance of the CertificateSubject class with the specified subject string.
string? Organization
Gets or sets the organization (O) of the certificate subject.
string CommonName
Gets or sets the common name (CN) of the certificate subject.
string? Locality
Gets or sets the locality (L) of the certificate subject.
string? OrganizationalUnit
Gets or sets the organizational unit (OU) of the certificate subject.
string? Country
Gets or sets the country (C) of the certificate subject.
string? State
Gets or sets the state or province (ST) of the certificate subject.
CertificateSubject(X509Certificate2 certificate)
Initializes a new instance of the CertificateSubject class with the specified X509Certificate2 certif...
CertificateSubject(string commonName, string? email, string? organization, string? organizationalUnit, string? locality, string? state, string? country)
Initializes a new instance of the CertificateSubject class with the specified properties.
override string ToString()
Generates a comma-delimited string representation of the certificate subject.