CryptSetProviderExA function (wincrypt.h)

Important  This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.
The CryptSetProviderEx function specifies the default cryptographic service provider (CSP) of a specified provider type for the local computer or current user.
Note  Typical applications do not use this function. It is intended for use solely by administrative applications.


BOOL CryptSetProviderExA(
  [in] LPCSTR pszProvName,
  [in] DWORD  dwProvType,
  [in] DWORD  *pdwReserved,
  [in] DWORD  dwFlags


[in] pszProvName

The name of the new default CSP. This must be a CSP installed on the computer. For a list of available cryptographic providers, see Cryptographic Provider Names.

[in] dwProvType

The provider type of the CSP specified by pszProvName.

[in] pdwReserved

This parameter is reserved for future use and must be NULL.

[in] dwFlags

The following flag values are defined.

Value Meaning
Can be used in conjunction with CRYPT_MACHINE_DEFAULT or CRYPT_USER_DEFAULT to delete the default.
Causes the user-context default CSP of the specified type to be set.
Causes the computer default CSP of the specified type to be set.

Return value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError. Possible error codes include those shown in the following table.

Return code Description
One of the parameters contains a value that is not valid. This is most often a pointer that is not valid.
The operating system ran out of memory.


Most applications do not specify a CSP name when calling the CryptAcquireContext function; however, an application can specify a CSP name and thereby select a CSP with an appropriate level of security. Because calls to CryptSetProviderEx determine the CSP of a specified type used by all applications from that point on, CryptSetProviderEx must never be called without a user's consent.


The wincrypt.h header defines CryptSetProviderEx as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header wincrypt.h
Library Advapi32.lib
DLL Advapi32.dll

See also



Service Provider Functions