Skip to content

Latest commit

 

History

History
294 lines (234 loc) · 8.83 KB

nf-wincrypt-cryptgetdefaultproviderw.md

File metadata and controls

294 lines (234 loc) · 8.83 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:wincrypt.CryptGetDefaultProviderW
CryptGetDefaultProviderW function (wincrypt.h)
Finds the default cryptographic service provider (CSP) of a specified provider type for the local computer or current user. (Unicode)
CRYPT_MACHINE_DEFAULT
CRYPT_USER_DEFAULT
CryptGetDefaultProvider
CryptGetDefaultProvider function [Security]
CryptGetDefaultProviderW
_crypto2_cryptgetdefaultprovider
security.cryptgetdefaultprovider
wincrypt/CryptGetDefaultProvider
wincrypt/CryptGetDefaultProviderW
security\cryptgetdefaultprovider.htm
security
5d15641e-1ad7-441d-9423-65fd51de9812
12/05/2018
CRYPT_MACHINE_DEFAULT, CRYPT_USER_DEFAULT, CryptGetDefaultProvider, CryptGetDefaultProvider function [Security], CryptGetDefaultProviderA, CryptGetDefaultProviderW, _crypto2_cryptgetdefaultprovider, security.cryptgetdefaultprovider, wincrypt/CryptGetDefaultProvider, wincrypt/CryptGetDefaultProviderA, wincrypt/CryptGetDefaultProviderW
wincrypt.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
CryptGetDefaultProviderW (Unicode) and CryptGetDefaultProviderA (ANSI)
Advapi32.lib
Advapi32.dll
Windows
19H1
CryptGetDefaultProviderW
wincrypt/CryptGetDefaultProviderW
c++
APIRef
kbSyntax
DllExport
Advapi32.dll
API-MS-Win-Security-cryptoapi-l1-1-0.dll
cryptsp.dll
CryptGetDefaultProvider
CryptGetDefaultProviderA
CryptGetDefaultProviderW

CryptGetDefaultProviderW function

-description

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 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.

-parameters

-param dwProvType [in]

The provider type for which the default CSP name is to be found.

Defined provider types are as follows:

-param pdwReserved [in]

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

-param 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.

-param 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.

-param 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.
 

-returns

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
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_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
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);

}

Note

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

-see-also

CryptSetProvider

CryptSetProviderEx

Service Provider Functions