Partager via


CryptGetDefaultProvider (Windows CE 5.0)

Send Feedback

This function finds the default cryptographic service provider (CSP) of a specified type either for the current user or the device. The name of the default CSP for the type specified in the dwProvType parameter is returned in the pszProvName buffer.

BOOL WINAPI CryptGetDefaultProvider( DWORDdwProvType,DWORD* pdwReserved,DWORDdwFlags,LPTSTRpszProvName,DWORD* pcbProvName);

Parameters

  • dwProvType
    [in] Specifies the provider type of the CSP specified by the pszProvName parameter. Possible provider types are defined for the CRYPT_KEY_PROV_INFO stucture.

  • pdwReserved
    [in] Reserved for future use and must be set to NULL.

  • dwFlags
    [in] Bitmask of flags. The following table shows the possible values for this parameter.

    Value Description
    CRYPT_MACHINE_DEFAULT Returns the device default CSP of the given type.
    CRYPT_USER_DEFAULT Returns the user default CSP of the given type.
  • pszProvName
    [out] Pointer to a buffer that receives the null-terminated string name of the default CSP. This parameter can be NULL to set the size of the name for memory allocation purposes.

  • pcbProvName
    [in, out] On input, pointer to a DWORD value that specifies the size, in bytes, of the buffer pointed to by the pszProvName parameter. On output, the DWORD value contains the number of bytes stored in the buffer.

    When processing the data returned in the buffer, applications must use the actual size of the data returned. The actual size may 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 will fit 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 Values

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

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

Value Description
ERROR_INVALID_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.
ERROR_MORE_DATA The buffer for the name is not large enough.
ERROR_NOT_ENOUGH_MEMORY The operating system ran out of memory.
NTE_BAD_FLAGS dwFlags has an unrecognized value.

Remarks

This function determines which installed CSP is currently set as the default for the current user or the machine. This information is most often used for display to the user.

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

Example Code

LPTSTR pszName;
DWORD cbName;

// Get the name of the default CSP specified for the PROV_RSA_SIG 
// type for the machine.
cbName = 0;
if (!CryptGetDefaultProvider(PROV_RSA_SIG, NULL, CRYPT_MACHINE_DEFAULT,
 NULL, &cbName)) 
 {printf("Error %x during CryptGetDefaultProvider!\n", GetLastError);
 return;
 }

if (NULL == (pszProvName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbName))) 
 {printf("Error during memory allocation\n");
 return;
 }

if (!CryptGetDefaultProvider(PROV_RSA_SIG, NULL, CRYPT_MACHINE_DEFAULT,
 NULL, &cbName)) 
 {printf("Error %x during CryptGetDefaultProvider!\n", GetLastError);
 return;
 }

// Display this information to the user
...

Requirements

OS Versions: Windows CE 2.10 and later.
Header: Wincrypt.h.
Link Library: Coredll.lib.

See Also

CryptSetProviderEx | CryptSetProvider

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.