从专有名称中提取通用名称

编程入门 行业动态 更新时间:2024-10-24 22:20:36
本文介绍了从专有名称中提取通用名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

.NET 中是否有从 rfc-2253 编码的专有名称解析 CN 的调用?我知道有一些第三方库可以做到这一点,但如果可能的话,我更愿意使用本机 .NET 库.

Is there a call in .NET that parses the CN from a rfc-2253 encoded distinguished name? I know there are some third-party libraries that do this, but I would prefer to use native .NET libraries if possible.

字符串编码的DN示例

CN=L.Eagle,O=Sue, Grabbit and Runn,C=GB

CN=L. Eagle,O=Sue, Grabbit and Runn,C=GB

CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM

CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM

推荐答案

如果您使用的是 X509Certificate2,则可以使用本机方法来提取简单名称.简单名称相当于主证书的主题字段中的通用名称 RDN:

If you are working with an X509Certificate2, there is a native method that you can use to extract the Simple Name. The Simple Name is equivalent to the Common Name RDN within the Subject field of the main certificate:

x5092Cert.GetNameInfo(X509NameType.SimpleName, false);

或者,X509NameType.DnsName 可用于检索主题备用名称(如果存在);否则,它将默认为通用名称:

Alternatively, X509NameType.DnsName can be used to retrieve the Subject Alternative Name, if present; otherwise, it will default to the Common Name:

x5092Cert.GetNameInfo(X509NameType.DnsName, false);

更多推荐

从专有名称中提取通用名称

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

发布评论

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

>www.elefans.com

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