Created
August 20, 2018 08:58
-
-
Save dalion619/21070c904e04c626b50be1b4d93dd38f to your computer and use it in GitHub Desktop.
X509Certificate2 Subject Alternative Names Extension Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<string> GetSubjectAlternativeNames(this X509Certificate2 certificate) | |
{ | |
foreach (X509Extension extension in certificate.Extensions) | |
{ | |
// Create an AsnEncodedData object using the extensions information. | |
AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData); | |
if (string.Equals(extension.Oid.FriendlyName, "Subject Alternative Name")) | |
{ | |
//Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName); | |
//Console.WriteLine("Oid value: {0}", asndata.Oid.Value); | |
//Console.WriteLine("Raw data length: {0} {1}", asndata.RawData.Length, Environment.NewLine); | |
//Console.WriteLine(asndata.Format(true)); | |
return new List<string>( | |
asndata.Format(true).Split(new string[] { "\r\n", "DNS Name=" }, | |
StringSplitOptions.RemoveEmptyEntries)); | |
} | |
} | |
return new List<string>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool I needed this, thx a lot!