CertSetContextProperty/CERT_KEY_PROV_INFO_PROP_ID

From: sunit (sunit_at_newsgroup.nospam)
Date: 10/27/05


Date: Thu, 27 Oct 2005 05:46:19 +0530

I used CertSetContextProperty with CERT_KEY_PROV_INFO_PROP_ID to add my Private key Blob(stored in a key container) in the Certificate Context. .

  But the program 's execution is halted at CertSetContextProperty and a dialog Box appears(OK and CANCEL).Even the Process is not terminated .To terminate the process I have to use Task Manager

/*here is the code*/

// Declare and initialize variables.for CRYPT_KEY_PROV_INFO
 CRYPT_KEY_PROV_INFO cryptprivkeyinfo;

  //store the name of the container
  cryptprivkeyinfo.pwszContainerName=L"saysnetsoft"; // name of the container
  
  //store the name of the CSP name ie MS_DEF_PROV_W
  cryptprivkeyinfo.pwszProvName= MS_DEF_PROV_W

  //provider type
  cryptprivkeyinfo.dwProvType =PROV_RSA_FULL;
 
  cryptprivkeyinfo.dwFlags = CERT_SET_KEY_CONTEXT_PROP_ID;

  cryptprivkeyinfo .rgProvParam=NULL;
  cryptprivkeyinfo.dwKeySpec=AT_SIGNATURE;

  const void *pvData=(LPVOID)&cryptprivkeyinfo;
  
  if(!(CertSetCertificateContextProperty(m_pCertContext,//pointer to the certificate context
                                                      CERT_KEY_PROV_INFO_PROP_ID,//get the private key from file
                                                      NULL,
                                                      pvData)))
  {
     ::OutputDebugString(TEXT("error:CertSetCertificateContextProperty.\n"));
     
  }