CryptGetUserKey function (wincrypt.h)
Syntax
BOOL CryptGetUserKey(
[in] HCRYPTPROV hProv,
[in] DWORD dwKeySpec,
[out] HCRYPTKEY *phUserKey
);
Parameters
[in] hProv
HCRYPTPROV handle of a cryptographic service provider (CSP) created by a call to CryptAcquireContext.
[in] dwKeySpec
Identifies the private key to use from the key container. It can be AT_KEYEXCHANGE or AT_SIGNATURE.
Additionally, some providers allow access to other user-specific keys through this function. For details, see the documentation on the specific provider.
[out] phUserKey
A pointer to the HCRYPTKEY handle of the retrieved keys. When you have finished using the key, delete the handle by calling the CryptDestroyKey function.
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 codes prefaced by "NTE" are generated by the particular CSP being used. Some possible error codes follow.
Return code | Description |
---|---|
|
One of the parameters specifies a handle that is not valid. |
|
One of the parameters contains a value that is not valid. This is most often a pointer that is not valid. |
|
The dwKeySpec parameter contains a value that is not valid. |
|
The hProv parameter does not contain a valid context handle. |
|
The key requested by the dwKeySpec parameter does not exist. |
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 |