The code is like the following:
HCRYPTKEY LegitKeyToExport = PreviouslyCreatedDHPregenKey;
HCRYPTKEY NullEncryptionKey = NULL;
DWORD Flags = NULL;
DWORD DataSize = 0;
DWORD Last_Error = 0;
DWORD KeyType = PUBLICKEYBLOB;
BOOL Result = FALSE;
Result =
CryptExportKey(LegitKeyToExport,NullEncryptionKey,KeyType,Flags,NULL,&DataSize);
Last_Error = GetLastError();
LegitKey is a valid key that was generated in the step prior; which I
will be needing to export for DH key exchange. However, it keeps
returning error code 87. I am looking to use the unknown buffer size
option in order to make sure I have enough space, so I am putting a
NULL buffer in and expecting ERROR_MORE_DATA (234L) back so I can then
allocate the buffer and perform the call again. Can anyone see anything
in why it won't work?
Help very much appreciated.
Ben
The "LegitKeyToExport" was created as a 512bit (512<<16), DH Pregen
(CALG_DH_EPHEM, CRYPT_PREGEN), with exportable permissions
(CRYPT_EXPORTABLE) using the MS_DEF_DSS_DH_PROV/PROV_DSS_DH provider.
also for anyone in the future reading this, the results won't quite
make sense after this point as it will return TRUE (instead of FALSE
and setting the last error to ERROR_MORE_DATA). Any how...