Platform SDK: Cryptography

CPSetKeyParam

The CPSetKeyParam function customizes the operations of a key.

BOOL CPSetKeyParam(
  HCRYPTPROV hProv,        // in
  HCRYPTKEY hKey,          // in
  DWORD dwParam,           // in
  BYTE *pbData,            // in
  DWORD dwFlags            // in
);

Parameters

hProv
Handle to a particular key container within the CSP. This handle is obtained with a call to CPAcquireContext.
hKey
Handle to the target key on which to set parameters.
dwParam
The following table list currently defined dwParam values.
Value Contents of the pbData buffer
KP_SALT A BYTE array containing the key's current salt value.
KP_SALT_EX A BYTE array containing the key's current salt value.

This parameter is not used with public/private key pairs. If hKey references a public/private key pair, the NTE_BAD_TYPE error code is returned.

KP_
PERMISSIONS
A DWORD defining the key's permission flags. Flags can be combined using bitwise OR operations.

See the table in the Remarks section for key permission flag values and their meanings.

KP_IV A BYTE array containing the key's current initialization Vector (IV).
KP_PADDING A DWORD indicating the padding method used by the key's cipher. PKCS5_PADDING is the only padding method value defined. It represents PKCS 5 ( sec 6.2) padding.
KP_MODE A DWORD indicating the cipher mode.

See the Remarks section for a table of possible cipher modes.

KP_MODE_BITS A DWORD indicating the feedback width, in bits. This parameter only applies when the OFB or CFB cipher modes are used.
KP_EFFECTIVE_
KEYLEN
A Microsoft base provider implementation compatible CSP using RC2 must support KP_EFFECTIVE_KEYLEN used to set the effective key length of an RC2 key.

Parameters can be added as needed. General-purpose parameters can be define in coordination with Microsoft to promote cross-vendor standardization and allow the new parameter numbers to be added to the standard Microsoft Win32® header files..

pbData
Parameter data buffer. Upon entry to the function, this buffer will contain the data that corresponds to the dwParam parameter value. Notice that the length of this data is not explicitly specified but is implied by the dwParam parameter value.
dwFlags
No flags are currently defined.

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_FLAGS The dwFlags parameter is non-zero or the pbData buffer contains an invalid value.
NTE_BAD_TYPE The dwParam parameter specifies an unknown parameter.
NTE_BAD_UID The CSP context that was specified when the hKey key was created cannot now be found.
NTE_FAIL The function failed in some unexpected manner.

Remarks

The following table lists the defined permission flags:

Permission flag Description
CRYPT_ENCRYPT Allows encryption
CRYPT_DECRYPT Allows decryption
CRYPT_EXPORT Allows key to be exported
CRYPT_READ Allows parameters to be read
CRYPT_WRITE Allows parameters to be set
CRYPT_MAC Allows MACs to be used with key

The following table lists the defined cipher modes:

Cipher mode Description
CRYPT_MODE_ECB Electronic codebook
CRYPT_MODE_CBC Cipher block chaining
CRYPT_MODE_OFB Output feedback mode
CRYPT_MODE_CFB Cipher feedback mode

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

CPGenKey, CPGetKeyParam, CryptSetKeyParam