NCryptOpenStorageProvider function (ncrypt.h)

The NCryptOpenStorageProvider function loads and initializes a CNG key storage provider.


SECURITY_STATUS NCryptOpenStorageProvider(
  [out]          NCRYPT_PROV_HANDLE *phProvider,
  [in, optional] LPCWSTR            pszProviderName,
  [in]           DWORD              dwFlags


[out] phProvider

A pointer to a NCRYPT_PROV_HANDLE variable that receives the provider handle. When you have finished using this handle, release it by passing it to the NCryptFreeObject function.

[in, optional] pszProviderName

A pointer to a null-terminated Unicode string that identifies the key storage provider to load. This is the registered alias of the key storage provider. This parameter is optional and can be NULL. If this parameter is NULL, the default key storage provider is loaded. The following values identify the built-in key storage providers.

Value Meaning
L"Microsoft Software Key Storage Provider"
Identifies the software key storage provider that is provided by Microsoft.
L"Microsoft Smart Card Key Storage Provider"
Identifies the smart card key storage provider that is provided by Microsoft.
L"Microsoft Platform Crypto Provider"
Identifies the TPM key storage provider that is provided by Microsoft.

[in] dwFlags

Flags that modify the behavior of the function. No flags are defined for this function.

Return value

Returns a status code that indicates the success or failure of the function.

Possible return codes include, but are not limited to, the following.

Return code Description
The function was successful.
The dwFlags parameter contains one or more flags that are not supported.
One or more parameters are not valid.
A memory allocation failure occurred.


In the case that an error condition is returned, the provider will have been unloaded from memory. Functions within the provider must not be called after a failure error is returned.

A service must not call this function from its StartService Function. If a service calls this function from its StartService function, a deadlock can occur, and the service may stop responding.


Requirement Value
Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header ncrypt.h
Library Ncrypt.lib
DLL Ncrypt.dll