CPGetUserKey

The CPGetUserKey function retrieves a handle to one of the permanent key pairs in the hProv key container, such as the key exchange key pair.

BOOL CPGetUserKey(
  HCRYPTPROV hProv,     // in
  DWORD dwKeySpec,      // in
  HCRYPTKEY *phUserKey  // out
);
 

Parameters

hProv
Handle to a particular key container (or "context") within the CSP. This handle is obtained via a call to CPAcquireContext.
dwKeySpec
Specification of the key to retrieve. The following key pair types are currently defined:
phUserKey
Address to which the function copies the handle of the retrieved key.

Return Values

If the function succeeds, TRUE should be returned; otherwise, return FALSE. When FALSE is returned, the appropriate error code (see the following table) must be set via SetLastError.

Error Description
NTE_BAD_KEY The key specified by the hKey parameter is invalid.
NTE_BAD_UID The CSP context that was specified when the key was created cannot now be found.
NTE_NO_KEY The key specified by the dwKeySpec parameter does not exist.

See Also

CPExportKey, CPGenKey, CryptGetUserKey