how can i export the private key as PKCS#7 ?
- From: "wuhao" <wuhao@xxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 17:38:39 +0800
CryptExportKey export the privatekey,but it seemed the format is pkcs11,
i have tried CryptExportPKCS8,but but what's private key OID for my
certificate request?
//here are my source code
void exportPrivateKey(HCRYPTPROV &hCryptProv,DWORD &dwKeySpec,PCCERT_CONTEXT
&pSignerCertContext)
{
HCRYPTKEY phUserKey;
BYTE *pbKeyBlob;
DWORD dwBlobLen;
//CryptGetUserKey(hCryptProv,dwKeySpec,&phUserKey);
if(CryptExportPKCS8(
hCryptProv,
dwKeySpec,
"wh-ok",
0,
NULL,
NULL,
&dwBlobLen))
{
printf("Size of the BLOB for the public key determined. \n");
}
else
{
MyHandleError("Error computing BLOB length.");
}
//--------------------------------------------------------------------
// Allocate memory for the pbKeyBlob.
if(pbKeyBlob = (BYTE*)malloc(dwBlobLen))
{
printf("Memory has been allocated for the BLOB. \n");
}
else
{
MyHandleError("Out of memory. \n");
}
//--------------------------------------------------------------------
// Do the actual exporting into the key BLOB.
if(CryptExportPKCS8(
hCryptProv,
dwKeySpec,
"wh-ok",
0x8000,
NULL,
pbKeyBlob,
&dwBlobLen))
{
printf("Contents have been written to the BLOB. \n");
}
else
{
MyHandleError("Error during CryptExportKey.");
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
FILE *fppp=fopen("pri.key","wb");
fwrite(pSignerCertContext->pbCertEncoded,1,pSignerCertContext->cbCertEncoded,fppp); fclose(fppp); ////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////}
.
- Follow-Ups:
- Re: how can i export the private key as PKCS#7 ?
- From: Mitch Gallant
- Re: how can i export the private key as PKCS#7 ?
- Prev by Date: RE: How to enable certificate purpose programmatically?
- Next by Date: Re: EFS certificate requirements
- Previous by thread: RE: How to enable certificate purpose programmatically?
- Next by thread: Re: how can i export the private key as PKCS#7 ?
- Index(es):