gpt4 book ai didi

c++ - 提取证书中主题属性的所有值

转载 作者:可可西里 更新时间:2023-11-01 13:27:58 24 4
gpt4 key购买 nike

我目前正在使用 CertGetNameString像这样提取每个主题属性的值:

CertGetNameString(pCertificate,
CERT_NAME_ATTR_TYPE,
0,
szOID_ORGANIZATIONAL_UNIT_NAME,
buf,
_countof(buf));

但是,我发现一些证书的组织单位名称 (OU) 有多个值,CertGetNameString 只能读取第一个值。例如,这是 Adob​​e 证书的主题:

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"

如果需要单个属性值,则可以对其进行解析。

关于c++ - 提取证书中主题属性的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9496239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com