C# Получаем короткое имя из Subject сертификата


public static string GetSubjectCN(X509Certificate2 cert)
        {
            // вырезаем имя из строки            
            int indexStart = cert.Subject.IndexOf("CN");
            if (indexStart >= 0)
            {
                int indexEnd = cert.Subject.IndexOf(",", indexStart);
                indexStart += 3;
                if (indexStart < indexEnd)
                {
                    return cert.Subject.Substring(indexStart, indexEnd - indexStart);
                }
            }
            return null;
        }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.