I am trying to create a new certificate store in Windows programmatically using C/C++.
I started with this function - CryptAcquireContext
, and wrote this piece of code:
#include<windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HCRYPTPROV hCryptProvider;
PCWSTR DefaultContainerName = L"MyStoreName";
PCWSTR DefaultProviderName = MS_STRONG_PROV;
DWORD DefaultProviderType = PROV_RSA_FULL;
DWORD DefaultProviderFlags = CRYPT_MACHINE_KEYSET | CRYPT_SILENT | CRYPT_NEWKEYSET;
printf("%d\n", CryptAcquireContext(&hCryptProvider, DefaultContainerName, DefaultProviderName, DefaultProviderType, DefaultProviderFlags));
return 0;
}
The container name and provider name values have been picked up from a design document that I am supposed to follow.
I dont know if this is the correct way to create stores, because after running this and opening the Certificate snap-in of MMC, I do not see the store of the given name. The program prints 1 on being run first time, and 0 from the second time onward.
Is this the correct way ? If yes, why don't I see the store in MMC ? If no, what is the correct way to create new certificate stores using C/C++ ?
Please feel free to point out any mistakes in the code.
CryptAcquireContext
can create a key container. A key container is not the same thing as a certificate store.To create a certificate store use
CertRegisterPhysicalStore
orCertRegisterSystemStore
.