vc通过COM方式调用CertEnroll

通过CertEnroll在CA上(1创建证书请求2得到证书3安装证书)



http://www.cnblogs.com/rippleyong/archive/2008/12/15/1355417.html 适用windows server 2008以上

http://www.cnblogs.com/stephenxie/articles/1114804.html

 

 

vc++

BSTR bstrDN = NULL;
BSTR bstrReq = NULL;
BSTR bstrOID = NULL;
ICEnroll4 * pEnroll = NULL;
HRESULT hr;

// initialize COM
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
if (FAILED(hr))
{
    printf("Failed CoInitializeEx - %x\n", hr);
    goto error;
}

hr = CoCreateInstance( __uuidof(CEnroll),
       NULL,
       CLSCTX_INPROC_SERVER,
       __uuidof(ICEnroll4),
       (void **)&pEnroll);
if (FAILED(hr))
{
    printf("Failed CoCreateInstance - pEnroll [%x]\n", hr);
    goto error;
}
// generate the DN for the cert request
bstrDN = SysAllocString( TEXT("CN=Your Name")   // common name
      TEXT(",OU=Your Unit")  // org unit
      TEXT(",O=Your Org")    // organization
      TEXT(",L=Your City")   // locality
      TEXT(",S=Your State")  // state
      TEXT(",C=Your Country") );  // country/region
if (NULL == bstrDN)
{
    printf("Memory allocation failed for bstrDN.\n");
    goto error;
}

// generate the OID, for example, "1.3.6.1.4.1.311.2.1.21".
bstrOID = SysAllocString(TEXT("<OIDHERE>"));
if (NULL == bstrOID)
{
    printf("Memory allocation failed for bstrOID.\n");
    goto error;
}

// create the PKCS10
hr = pEnroll->createPKCS10( bstrDN, bstrOID, &bstrReq );
if (FAILED(hr))
{
    printf("Failed createPKCS10 - %x\n", hr);
    goto error;
}
else
// do something with the PKCS10 (bstrReq);

error:

//clean up resources, etc.
if ( bstrDN )
SysFreeString( bstrDN );
if ( bstrOID )
SysFreeString( bstrOID );
if ( bstrReq )
SysFreeString( bstrReq );
if ( pEnroll )
pEnroll->Release();

CoUninitialize();

 

--------------------------------------------------------------

转载的文章,经测试支持windows2003、XP,不支持Win7、windows 2008

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值