1

Microsoft 提供的 Certificate Enrollment API 和 Cryptography API 使我们能够以编程方式应用证书并将其安装在本地计算机上。

参考windows SDK 7.0自带的示例代码(enrollWithICertRequest3),发现可以通过带有ICertRequest3接口的web服务申请证书。这很酷,但副作用是我们申请的证书必须安装在本地机器上,然后我们才能调用 createPFX 方法提取最终的证书文件(包含私钥)。

在深入研究 ICertRequest3 接口后,我找到了 GetCertificate 方法。但是我可以从这种方法中得到一个证书,其中包含“----begin cert--- ---end cert---”,其中不包含私钥信息。

我不知道我是否在这里说得足够清楚。所以我需要的是通过网络以编程方式申请证书,而不必在本地机器上安装它。最终的 pxf 文件是关键:(

以下是供您参考的示例代码片段。

    //Get full response for installation
    hr = request3_interface->GetFullResponseProperty(
        FR_PROP_FULLRESPONSENOPKCS7,    //[in] LONG PropId (FR_PROP_*)
        0,                              //[in] LONG PropIndex
        PROPTYPE_BINARY,                //[in] LONG PropType (PROPTYPE_*
        CR_OUT_BASE64,                  //[in] LONG Flags (CR_OUT_*)
        &var_fullresponse);             //[out, retval] VARIANT *pvarPropertyValue
    if(FAILED(hr))
        goto error;

    //Install the response
    hr = enroll2_interface->InstallResponse2(
        AllowNone,                  //[in] InstallResponseRestrictionFlags Restrictions
        var_fullresponse.bstrVal,   //[in] BSTR strResponse
        XCN_CRYPT_STRING_BASE64,    //[in] EnrodingType Encoding
        bstr_policyserver_password, //[in] BSTR strPassword
        bstr_policyserver_url,      //[in] BSTR strEnrollmentPolicyServerUrl
        bstr_policyserver_id,           //[in] BSTR strEnrollmentPolicyServerID
        PsfNone,                    //[in] PolicyServerUrlFlags EnrollmentPolicyServerFlags
        policy_server_authtype);        //[in] X509EnrollmentAuthFlags authFlags
    if(FAILED(hr))
        goto error;

    hr = enroll2_interface->CreatePFX(pwd, PFXExportEEOnly, XCN_CRYPT_STRING_BASE64, &cert_raw);
    if(FAILED(hr))
        goto error;

任何形式的建议将不胜感激。期待您的回复。

你的,

约旦

4

0 回答 0