Friday, January 22, 2010

Get subject common name from an X509Certificate2 object

Both Subject and SubjectName properties of X509Certificate2 have the full distinguished name (ex: “CN = Rags, OU = UserAccounts, DC = corp, O = microsoft”). But what if we only want the common name part of it (in this case “Rags”). This was unintuitive to find, but I finally figured out. You use

cert.GetNameInfo(X509NameType.SimpleName, false)

This prevents parsing the string etc and is certainly better!

4 comments:

Unknown said...

THANK YOU

Unknown said...

Thank you..!! for the Post, it saves my time. :)

raUltraHz said...

Thank you!!!

Ivan Ferrer said...

thanks for sharing