您如何从X509Certificate2解析主题备用名称?

编程入门 行业动态 更新时间:2024-10-23 17:33:17
本文介绍了您如何从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解析主题备用名称?

本文发布于:2023-11-05 08:26:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   主题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!