1

I am trying to store the key in TPM using CNG NCryptOpenStorageProvide "MS_PLATFORM_CRYPTO_PROVIDER".

Please any one help on How to use CNG functions for accessing TPM read and Write.

Bruno Martinez
  • 2,850
  • 2
  • 39
  • 47

1 Answers1

1

Assuming by "store a key in TPM" you mean "create a persisted key in the TPM":

NCRYPT_PROV_HANDLE hProv = NULL;
NCRYPT_KEY_HANDLE hKey = NULL;
PCWSTR keyName = L"MyKey";

NCryptOpenStorageProvider(
        &hProv,
        MS_PLATFORM_CRYPTO_PROVIDER,
        0);
NCryptCreatePersistedKey(
        hProv,
        &hKey,
        BCRYPT_RSA_ALGORITHM,
        keyName,
        0,
        NCRYPT_OVERWRITE_KEY_FLAG);
NCryptFinalizeKey(hKey, 0);

Obviously you should check the return code of each invoked function.

mnistic
  • 10,866
  • 2
  • 19
  • 33