gpt4 book ai didi

c++ - 使用 CryptoApi 向证书添加扩展名

转载 作者:太空宇宙 更新时间:2023-11-04 04:26:40 24 4
gpt4 key购买 nike

我正在尝试使用 CryptoApi 向证书请求添加扩展。这是我使用的代码:

char extensionValue[] = "testValue";


_CRYPTOAPI_BLOB myBlob = {
(DWORD)strlen(extensionValue),
(BYTE*)extensionValue
};

wchar_t pszString[1000];
DWORD dwLength = 1000;
bool checkEncodingToBase64Test = CryptBinaryToStringW(myBlob.pbData, myBlob.cbData, CRYPT_STRING_BASE64, (LPWSTR)pszString, &dwLength);


BSTR bstrValue = pszString;
BSTR bstrName = SysAllocString(L"1.2.643.100.111");

HRESULT checkAddingExtention = pEnroll->addExtensionToRequest(0, bstrName, bstrValue);

我使用 https://certlogik.com/decoder/ 检查请求在这里检查时得到这个结果:

Requested Extensions:
X509v3 Extended Key Usage:
TLS Web Client Authentication, E-mail Protection, 1.2.643.2.2.34.6
X509v3 Key Usage:
Digital Signature, Non Repudiation, Key Encipherment, Data Encipherment
1.2.643.100.111:
testValue

SEQUENCE {:
OBJECT IDENTIFIER '1 2 643 100 111'
OCTET STRING 74 65 73 74 56 61 6C 75 65
}

但我需要得到这种类型的结构:

SEQUENCE {
OBJECT IDENTIFIER '1 2 643 100 111'
OCTET STRING, encapsulates {
UTF8String
'testValue'
}
}

如何实现?如何将 UTF8 字符串放入扩展中?

最佳答案

尝试这样做

WCHAR *id = L"testValue";
CERT_NAME_VALUE otherNameValue = { CERT_RDN_UTF8_STRING, (DWORD)wcslen(id) * sizeof(wchar_t), (PBYTE)id };

BYTE *buf;
DWORD size = 0;
CryptEncodeObjectEx(PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, X509_ANY_STRING, &otherNameValue, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);

CERT_EXTENSION CertExtension[] = { {"1.2.643.100.111", FALSE, size, buf} };

...
LocalFree(buf);

关于c++ - 使用 CryptoApi 向证书添加扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40844688/

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