How would I extract the public and private key and put them into seperate blobs? So after I use
if (!CryptGenKey(hProv, CALG_RC4, CRYPT_EXPORTABLE, &hSessionKey))

It puts the Keys into SessionKey, but what if I want to extract both the public and private key from hSessionKey, how can i do this?

7 Years
Discussion Span
Last Post by raptr_dflo

It looks like you can export the public-key into a BLOB using CryptExportKey() (http://msdn.microsoft.com/en-us/library/aa379931%28v=vs.85%29.aspx), but then the BLOB is only usable via CryptImportKey(). You can also export/import the public/private key combo. The private key is private, thus there is no way to export it separately.

Instead, you're supposed to use the opaque HCRYPTKEY handle returned from CryptGenKey() (or CryptImportKey(), assuming you've already generated a key) to encrypt data to be sent or to decrypt data received.

You may find what you're looking for in the sample code here:
or in the other sidebar links.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.