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() (, 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.