Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function specifies the current user default cryptographic service provider (CSP). Typical applications do not use this function. It is intended for use solely by administrative applications.

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

Syntax

BOOL CRYPTFUNC CryptSetProvider( 
  LPCTSTR 
pszProvName,
  DWORD 
dwProvType
);

Parameters

pszProvName

[in] Pointer to the null-terminated string that contains the name of the new default CSP. This must be a CSP installed on the computer.

dwProvType

[in] Specifies the provider type of the CSP defined in the pszProvNameparameter.

Return Value

TRUE indicates success. FALSE indicates failure. To get extended error information, call the GetLastErrorfunction.

The following table shows the common values for the GetLastErrorfunction. The error values prefaced by NTE are generated by the particular CSP you are using.

Value Description

ERROR_INVALID_HANDLE

One of the parameters specifies an invalid handle.

ERROR_INVALID_PARAMETER

One of the parameters contains an invalid value. This is most often an illegal pointer.

ERROR_NOT_ENOUGH_MEMORY

The operating system ran out of memory during the operation.

Error values returned from the RegCreateKeyExfunction.

See RegCreateKeyEx.

Error values returned from the RegSetValueExfunction.

See RegSetValueEx.

Remarks

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

Because calling the CryptSetProviderfunction determines the CSP of a specified type used by all applications that run from that point on, this function must not be called without the consent of the user.

Windows Embedded CE does not support the ANSI version of this function.

Example Code

Copy Code
HCRYPTPROV hProv = 0;
// Specify the default PROV_RSA_SIG provider. Note that this
assumes
// that a CSP with a type of PROV_RSA_SIG and named "Joe's
Provider"
// has already been installed.
if(!CryptSetProvider(TEXT("Joe's Provider"), PROV_RSA_SIG)) {
 printf("Error %x during CryptSetProvider!\n", GetLastError());
 return;
}
// Get a handle to the provider that you just made the default
using CryptAcquireContext.
// For sample code, see <A
HREF="wce50lrfcryptacquirecontext.htm">CryptAcquireContext</A>.
...
...
// Free the provider handle.
if(!CryptReleaseContext(hProv, 0)) {
 printf("Error %x during CryptReleaseContext!\n", GetLastError());
 return;
}

Requirements

Header wincrypt.h
Library coredll.lib
Windows Embedded CE Windows CE 2.10 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also