The CPGetKeyParam function is used by applications to retrieve data that governs the operations of a key.
BOOL CPGetKeyParam(
HCRYPTPROV hProv, // in
HCRYPTKEY hKey, // in
DWORD dwParam, // in
BYTE *pbData, // out
DWORD *pdwDataLen, // in, out
DWORD dwFlags // in
);
If this parameter is NULL, then no parameter data should be copied. Instead, the required buffer size (in bytes) should be returned in pdwDataLen. This is not an error.
If the buffer specified by pbData is not large enough to hold the requested data, the ERROR_MORE_DATA error code should be returned via the SetLastError function. In this case, the required buffer size must be returned in pdwDataLen.
If this function fails with any error code other than ERROR_MORE_DATA, zero should be returned in this parameter.
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 |
---|---|
ERROR_MORE_DATA | The pbData buffer is not large enough to hold the requested data. |
NTE_BAD_FLAGS | The dwFlags parameter is non-zero. |
NTE_BAD_KEY or NTE_NO_KEY | The key specified by the hKey parameter is invalid. |
NTE_BAD_TYPE | The dwParam parameter specifies an unknown parameter number. |
NTE_BAD_UID | The CSP context that was specified when the key was created cannot now be found. |
For all key types, the dwParam value can be set to one of the following key parameter types:
If hKey references a public/private key pair, a DWORD value indicating the key pair's encryption granularity in bits should be placed in the pbData buffer. For RSA key pairs, this will be the size of the modulus. If the public-key algorithm does not support encryption, the NTE_BAD_TYPE error code should be returned.
This parameter does not apply to public/private key pairs. If hKey references a public/private key pair, the NTE_BAD_TYPE error code should be returned.
The following table lists the permission flags that are currently defined.
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 |
If the hKey parameter refers to a block cipher session key, the dwParam value may also be set to one of the following parameter types:
The following padding mode is currently defined:
PKCS5_PADDING—PKCS 5 (sec 6.2) padding method.
The following table lists the cipher modes that are currently defined.
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 |
This parameter only applies when the OFB or CFB cipher modes are used.
Additional parameters can be added as needed. If these are general-purpose in nature, rather than applying to a single provider type, you should define these in coordination with Microsoft. This will promote cross-vendor standardization, and allow the new parameter numbers to be added to the standard Microsoft Win32® header files.
CPSetKeyParam, CryptGetKeyParam