Extract Common Name from Distinguished Name(从专有名称中提取通用名称)
问题描述
.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);
这篇关于从专有名称中提取通用名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从专有名称中提取通用名称
基础教程推荐
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
