[Q] How to get "CN" attribute from a certificate ?
X509Certificate2 cert;
...
cert.SubjectName.Name= "CN= ..., OU= ..."
[try] my primitive approach ...
//=== C# code snippet
public string getCN( X509Certificate2 cert)
{
string s = cert.SubjectName.Name;
string[] strArr=s.Split(new char[] { ',' });
for (int i = 0; i < strArr.Length; i++)
{
if (strArr[i].Contains("CN"))
{
s = strArr[i];
int pos = s.IndexOf('=');
s=s.Substring(pos + 1);
break;
}
}
return s
}
沒有留言:
張貼留言