Re: how can i export the private key as PKCS#7 ?
- From: "Mitch Gallant" <jensigner@xxxxxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 07:15:50 -0400
CryptExportKey() exports MS-specific format keyblobs.
For CryptExportPKCS8(), for the usual default OID you can use is:
String szOID_RSA_RSA ="1.2.840.113549.1.1.1" ;
See source code here for an implementation (in .NET but usage of capi
function parameters is same in C code):
http://www.jensign.com/KeyPal
- Mitch Gallant
MVP Security
"wuhao" <wuhao@xxxxxxxxxxx> wrote in message
news:OhjoJwEaGHA.3612@xxxxxxxxxxxxxxxxxxxxxxx
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: wuhao
- Re: how can i export the private key as PKCS#7 ?
- References:
- how can i export the private key as PKCS#7 ?
- From: wuhao
- how can i export the private key as PKCS#7 ?
- Prev by Date: Re: EFS certificate requirements
- Next by Date: Access Violation Releasing CComPtr<IAzAuthorizationStore>
- Previous by thread: how can i export the private key as PKCS#7 ?
- Next by thread: Re: how can i export the private key as PKCS#7 ?
- Index(es):
Relevant Pages
|