如何使用CryptoAPI从p7b证书中提取公钥
||
我有一个p7b证书存储。我用
$HCERTSTORE cert_store_handle = CertOpenStore(
CERT_STORE_PROV_PKCS7,
PKCS_7_ASN_ENCODING,
NULL,
CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG,
&opm_data_blob
);
我进行证书链验证,然后确定,直到必须从叶子证书中提取公钥为止。
我打电话
CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, RSA_CSP_PUBLICKEYBLOB, (BYTE*) pubkey + 46, pubkey_len - 46, CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG, NULL, &pubkey_decoded_size);
但它会返回ASN1错误标签错误。
所以我尝试下面的代码:
{
BOOL crypt_res = FALSE;
HCRYPTPROV crypt_prov_hndl = NULL;
crypt_res = CryptAcquireContext(&crypt_prov_hndl, NULL, NULL, PROV_RSA_FULL, 0/*CRYPT_NEWKEYSET*/);
if (!crypt_res) {
HRESULT decode_hr = __HRESULT_FROM_WIN32(GetLastError());
return decode_hr;
}
HCRYPTKEY crypt_key_hndl = NULL;
crypt_res = CryptImportPublicKeyInfoEx(crypt_prov_hndl, X509_ASN_ENCODING, signer_public_key, CALG_RSA_SIGN, 0, NULL, &crypt_key_hndl);
if (!crypt_res) {
HRESULT decode_hr = __HRESULT_FROM_WIN32(GetLastError());
return decode_hr;
}
crypt_res = CryptReleaseContext(crypt_prov_hndl, 0);
}
并且工作正常,但我仍然不知道如何提取公钥。
有什么建议么?
没有找到相关结果
已邀请:
1 个回复
烫珊