正在提取证书中主题属性的所有值
Extracting all values of a subject attribute in a certificate
我目前正在使用CertGetNameString
来提取每个主题属性的值,比如:
CertGetNameString(pCertificate,
CERT_NAME_ATTR_TYPE,
0,
szOID_ORGANIZATIONAL_UNIT_NAME,
buf,
_countof(buf));
但是,我发现一些证书的组织单位名称(OU)有多个值,CertGetNameString
只能读取第一个值。例如,这是Adobe证书的主题:
CN = Adobe Systems, Incorporated
OU = Acrobat Engineering
OU = Digital ID Class 3 - Microsoft Software Validation v2
O = Adobe Systems, Incorporated
L = San Jose
S = California
C = US
如何使用CryptoAPI读取OU(和其他)属性的所有值?
好的,找到了解决方案。正确使用的API是CertNameToStr
,如下所示:
CertNameToStr(X509_ASN_ENCODING,
&pCertificate->pCertInfo->Subject,
CERT_X500_NAME_STR,
buf,
_countof(buf));
它将返回一个字符串,例如:
C=US, S=California, L=San Jose, O="Adobe Systems, Incorporated", OU=Digital ID Class 3 - Microsoft Software Validation v2, OU=Acrobat Engineering, CN="Adobe Systems, Incorporated"
如果需要单独的属性值,则可以对其进行解析。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么istream不支持右值提取
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- 如何设置一个范围来提取我想要获得的信息
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- 按属性搜索和提取 XML 节点
- 如何从对象数组中提取属性数组?
- 如何使用Boost C 属性映射从配置文件中提取值
- 从 QDomDocument 中提取属性值
- 正在提取证书中主题属性的所有值
- 如何从文件中提取文件属性/元数据/注释?
- 使用Boost.从HTML中提取某些标签/属性