int _tmain(int argc, _TCHAR* argv[])
{
	DWORD dwIndex = 0;
	DWORD dwFlags = 0;
	DWORD dwProvType;
	DWORD cbName;
	LPTSTR pszName;

	while(CryptEnumProviderTypes(dwIndex,NULL,dwFlags,&dwProvType,NULL,&cbName)){
		pszName = (LPTSTR)malloc(cbName);
		CryptEnumProviderTypes(dwIndex,NULL,dwFlags,&dwProvType,pszName,&cbName);
		printf("%s\r\n",pszName);
		dwIndex++;
		free(pszName);
	}
	CCSPUtil* csputil = new CCSPUtil();
	int size; 
	csputil->GetProvider(NULL,0,&size);
	char* provider = (char*)malloc(size);
	csputil->GetProvider(provider,0,&size);
	printf("%d\r\n",size);
	printf("%s\r\n",provider);

	csputil->ListCertInStore();
	csputil->AddCertToStore();
	int d;
	scanf("%d",&d);
	
	return 0;
}
Exemple #2
0
/**
 * Performs all necessary steps to initialize the crypto library
 */
void crypto_init(int set_sys_key)
{
    DWORD tmp_prov_type, name_len;
    int cnt, found_aes, i;

    // First see if we have an AES capable provider.
    // If so, use that, otherwise use one without.
#ifdef PROV_RSA_AES
    found_aes = 0;
    cnt = 0;
    name_len = 0;
    while (CryptEnumProviderTypes(cnt, 0, 0, &tmp_prov_type, NULL, &name_len) &&
           (!found_aes)) {
        if (tmp_prov_type == PROV_RSA_AES) {
            found_aes = 1;
        }
        cnt++;
        name_len = 0;
    }
    if ((!found_aes) && (GetLastError() != ERROR_NO_MORE_ITEMS)) {
        mserror("CryptEnumProviderTypes failed");
        exit(1);
    }
    prov_type = (found_aes ? PROV_RSA_AES : PROV_RSA_FULL);
#else
    prov_type = PROV_RSA_FULL;
#endif

    if (set_sys_key) {
        machine_keyset = CRYPT_MACHINE_KEYSET;
    } else {
        machine_keyset = 0;
    }
    if (!CryptAcquireContext(&base_prov, NULL, NULL, prov_type,
            CRYPT_VERIFYCONTEXT | machine_keyset)) {
        mserror("CryptAcquireContext failed");
        exit(1);
    }

    for (i = 0; i < MAXLIST; i++) {
        memset(&private_key_list[i], 0, sizeof(private_key_list[i]));
        memset(&symmetric_keys[i], 0, sizeof(symmetric_keys[i]));
        memset(&hmac_keys[i], 0, sizeof(hmac_keys[i]));
    }
    init_done = 1;
}