Is there a way to wrap or unwrap keys in CryptoApi? I tryed to set the key params CRYPT_IMPORT_KEY
and CRYPT_EXPORT_KEY
with the proper function, but I get the error "params undefined".
Other details:
The program is written in C++, OS: Win7, IDE: Dev-C++
The main headers are windows.h
and wincrypt.h
.
When I compile, i get the error " CRYPT_EXPORT_KEY (or CRYPT_IMPORT_KEY) undeclared".
Code I wrote:
flags = CRYPT_ENCRYPT | CRYPT_EXPORTABLE | CRYPT_DECRYPT | CRYPT_EXPORT_KEY;
//set the above permission to the session key "dkey"
CryptSetKeyParam(dKey,KP_PERMISSIONS,(BYTE*)&flags,0);
Update from the comments:
And it compiles! But the programs terminates with the error NTE_BAD_FLAGS
. It is because of CRYPT_EXPORT_KEY
flag!