Platform SDK: Cryptography

CPGetUserKey

The CPGetUserKey function retrieves the handle of one of the permanent key pairs in the hProv key container.

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

Parameters

hProv
Handle to a particular key container within the CSP. This handle is obtained with a call to CPAcquireContext.
dwKeySpec
Specification of the key to retrieve. The following key pair types are currently defined:
Key pair type Descriptipn
AT_KEYEXCHANGE Key used to encrypt and exchange session keys.
AT_SIGNATURE Keys used to create and verify digital signatues.

phUserKey
Address to which the function copies the handle of the retrieved key. This pointer must not be NULL.

Return Values

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE, and the appropriate error code from the following table must be set using 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.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 OSR2 or later (or Windows 95 with Internet Explorer 3.02 or later).
  Header: Declared in Wincrypt.h.

See Also

CPExportKey, CPGenKey, CryptGetUserKey