Beispiel #1
0
static char *DigiCrypt_GetDefaultKeyContainerNameSimple(char *psCSPName)
{
char *psRes = NULL;
HCRYPTPROV hProvider=0;
BOOL  fRes;
DWORD dwFlags = 0;
BYTE pbData[dNAME_ITEM_LEN+1];
DWORD cbData = dNAME_ITEM_LEN;
DWORD dwError;
fRes = OpenProvider(&hProvider, psCSPName, dwFlags);
//fRes = CryptAcquireContext(&hProvider,NULL,psCSPName,PROV_RSA_SIG, dwFlags);
if (fRes == TRUE)
  {
  fRes = CryptGetProvParam(hProvider, PP_CONTAINER, pbData, &cbData, 0);
  if (fRes == FALSE)
    dwError = GetLastError();
  }
if (fRes == TRUE)
  {
  lstrcpy(oG_sKeyContainerName,(const char *)pbData);
  psRes = oG_sKeyContainerName;
  DigiCrypt_ChangeContainerName(oG_sKeyContainerName);
  }
if (hProvider != 0)
  CryptReleaseContext(hProvider, 0);
return(psRes);
}
Beispiel #2
0
static char *DigiCrypt_GetDefaultKeyContainerName(char *psCSPName)
{
  char *psRes = NULL;
  HCRYPTPROV hProvider;
  BOOL  fRes;
  DWORD dwFlags = CRYPT_VERIFYCONTEXT;
  BYTE pbData[dNAME_ITEM_LEN+1];
  DWORD cbData = dNAME_ITEM_LEN;
  DWORD dwError;
  DWORD dwProvType;

  ZeroMemory(pbData,cbData);
  ZeroMemory(oG_sKeyContainerName,1000);
  dwProvType = DigiCrypt_FindContext_GetCSPType(psCSPName);
  //LOG("GetDefaultKeyContainerName CSP=%s",psCSPName);
  if (lstrcmp(psCSPName,psData_Extra_CSP_Name) != 0)
    fRes = CryptAcquireContext(&hProvider,NULL,psCSPName,dwProvType, CRYPT_SILENT);
  else
    fRes = CryptAcquireContext(&hProvider,NULL,psCSPName,dwProvType, CRYPT_VERIFYCONTEXT);
  if (fRes == FALSE && dwFlags == CRYPT_SILENT) {
    //by description must be CRYPT_VERIFYCONTEXT
    fRes = CryptAcquireContext(&hProvider,NULL,psCSPName,dwProvType, CRYPT_VERIFYCONTEXT);
  }
  if (fRes == TRUE) {
    cbData = dNAME_ITEM_LEN;
    fRes = CryptGetProvParam(hProvider, PP_CONTAINER, pbData, &cbData, 0);
    /*if (fRes == FALSE)
      dwError = GetLastError();*/
  }
  //Some cards should not have default key container
  //let try to find key containers on the card.
  if (fRes == FALSE)  {
    fRes=CryptGetProvParam(hProvider, PP_ENUMCONTAINERS, pbData, &cbData,CRYPT_FIRST);
    if (fRes == FALSE)
      dwError = GetLastError();
  }
  if (fRes == TRUE) {
    //oG_hProvider = hProvider;
    strncpy(oG_sKeyContainerName, (char *) pbData, sizeof(oG_sKeyContainerName));
    //psRes = oG_sKeyContainerName;
    DigiCrypt_ChangeContainerName(oG_sKeyContainerName);
  } else {
      
  }
  if (psRes != NULL)
    LOG("GetDefaultKeyContainerName CSP=%s",psCSPName);
  else
    LOG("GetDefaultKeyContainerName Not found");
  if (hProvider != 0)
    CryptReleaseContext(hProvider, 0);
  return(oG_sKeyContainerName);
}