I'm looking for the way to get the Email (string) from X509 Certificate. I can't find ready property or method for this. So the best for me (most flexible for future tasks) is to get the value by ASN OID (1.2.840.113549.1.9.1). How can I do this using native .NET class?
I tried to use AsnEncodedData.format
but without any effect. Is there a way to do this?
If it is ok to use 3rd party tools, then you may look at my Powershell PKI module. This module contains a PKI.Core.dll library which is a set of API. APIs are fairly well documented in the Library documentation
With thid library I would go with the following static method and custom class:
The method returns an array (unordered) of RDN attributes, where
OID
property contains RDN object identifier andValue
property contains RDN text value. If you can use Linq, then you can quickly search through collection:somearray.Where(x => x.OID.Value == "1.2.840.113549.1.9.1");
. Note that particular RDN attributes may appear multiple times, therefore you should not useFirst*
orSingle*
Linq methods.