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?

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:
http://msdn.microsoft.com/en-us/library/aa382370%28v=vs.85%29.aspx
or in the other sidebar links.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.