CryptGetDefaultProvider function
Applies to: desktop apps only
The CryptGetDefaultProvider function finds the default cryptographic service provider (CSP) of a specified provider type for the local computer or current user. The name of the default CSP for the provider type specified in the dwProvType parameter is returned in the pszProvName buffer.
Syntax
BOOL WINAPI CryptGetDefaultProvider( __in DWORD dwProvType, __in DWORD *pdwReserved, __in DWORD dwFlags, __out LPTSTR pszProvName, __inout DWORD *pcbProvName );
Parameters
- dwProvType [in]
-
The provider type for which the default CSP name is to be found.
Defined provider types are as follows:
- pdwReserved [in]
-
This parameter is reserved for future use and must be NULL.
- dwFlags [in]
-
The following flag values are defined.
Value Meaning - CRYPT_USER_DEFAULT
- 0x00000002
Returns the user-context default CSP of the specified type.
- CRYPT_MACHINE_DEFAULT
- 0x00000001
Returns the computer default CSP of the specified type.
- pszProvName [out]
-
A pointer to a null-terminated character string buffer to receive the name of the default CSP.
To find the size of the buffer for memory allocation purposes, this parameter can be NULL. For more information, see Retrieving Data of Unknown Length.
- pcbProvName [in, out]
-
A pointer to a DWORD value that specifies the size, in bytes, of the buffer pointed to by the pszProvName parameter. When the function returns, the DWORD value contains the number of bytes stored or to be stored in the buffer.
Note When processing the data returned in the buffer, applications must use the actual size of the data returned. The actual size can be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to ensure that the largest possible output data fits in the buffer.) On output, the variable pointed to by this parameter is updated to reflect the actual size of the data copied to the buffer.
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.
The error code prefaced by NTE is generated by the particular CSP being used. Possible error codes include the following.
| 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 buffer for the name is not large enough. |
|
The operating system ran out of memory. |
|
The dwFlags parameter has an unrecognized value. |
Remarks
This function determines which installed CSP is currently set as the default for the local computer or current user. This information is often displayed to the user.
Examples
The following example retrieves the name of the default CSP for the PROV_RSA_FULL provider type. For another example that uses this function, see Example C Program: Enumerating CSP Providers and Provider Types.
#include <stdio.h> #include <windows.h> #include <Wincrypt.h> #pragma comment(lib, "crypt32.lib") void main() { DWORD cbProvName=0; LPTSTR pbProvName=NULL; // Copyright (C) Microsoft. All rights reserved. // Get the length of the RSA_FULL default provider name. if (!(CryptGetDefaultProvider( PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, NULL, &cbProvName))) { printf("Error getting the length of the default " "provider name.\n"); exit(1); } // Allocate local memory for the name of the default provider. if (!(pbProvName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbProvName))) { printf("Error during memory allocation for " "provider name.\n"); exit(1); } // Get the default provider name. if (CryptGetDefaultProvider( PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, pbProvName, &cbProvName)) { printf("The default provider name is %s\n",pbProvName); } else { printf("Getting the name of the provider failed.\n"); exit(1); } // Free resources when done. LocalFree(pbProvName); }
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | CryptGetDefaultProviderW (Unicode) and CryptGetDefaultProviderA (ANSI) |
See also
Send comments about this topic to Microsoft
Build date: 3/6/2012