本文介绍了您如何从X509Certificate2解析主题备用名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法来从X509Certificate2对象获取主题备用名称?
Is there an easy way to get the Subject Alternate Names from an X509Certificate2 object?
foreach (X509Extension ext in certificate.Extensions) { if (ext.Oid.Value.Equals(/* SAN OID */"2.5.29.17")) { byte[] raw = ext.RawData; // ?????? parse to get type and name ???????? } }推荐答案
使用扩展名的格式化方法
X509Certificate2 cert = /* your code here */; foreach (X509Extension extension in cert.Extensions) { // Create an AsnEncodedData object using the extensions information. AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData); 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)); }更多推荐
您如何从X509Certificate2解析主题备用名称?
发布评论