CryptSetProviderW 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 CryptSetProvider function specifies the current user's default cryptographic service provider (CSP).

If a current user's default provider is set, that default provider is acquired by any call by that user to CryptAcquireContext specifying a dwProvType provider type but not a CSP name.

An enhanced version of this function, CryptSetProviderEx, is also available.

Note  Typical applications do not use this function. It is intended for use solely by administrative applications.
 

Syntax

BOOL CryptSetProviderW(
  [in] LPCWSTR pszProvName,
  [in] DWORD   dwProvType
);

Parameters

[in] pszProvName

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

[in] dwProvType

Provider type of the CSP specified by pszProvName.

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. Some possible error codes are listed in the following table.

Return code Description
ERROR_INVALID_HANDLE
One of the parameters specifies a handle that is not valid.
ERROR_INVALID_PARAMETER
One of the parameters contains a value that is not valid. This is most often a pointer that is not valid.
ERROR_NOT_ENOUGH_MEMORY
The operating system ran out of memory during the operation.
 

Errors can also be propagated from internal calls to RegCreateKeyEx and RegSetValueEx.

Remarks

Typical applications do not specify a CSP name when calling CryptAcquireContext; however, an application does have the option of selecting a specific CSP. This gives a user the freedom to select a CSP with an appropriate level of security.

Since calling CryptSetProvider determines the CSP of a specified type used by all applications that run from that point on, this function must not be called without users' consent.

Note

The wincrypt.h header defines CryptSetProvider 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.

Requirements

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

CryptAcquireContext

Cryptographic Provider Names

RegCreateKeyEx

RegSetValueEx

Service Provider Functions