Exporting a Diffie-Hellman/Schannel Agreed (secret) Key

    To export a Diffie-Hellman/Schannel agreed key
  1. Get a handle to a D-H provider. Do this by calling CryptAcquireContext to get a pointer to the Microsoft DH Schannel Cryptographic Provider.
  2. Get a handle to a D-H key. Do this by calling CryptGenKey (see Generating Diffie-Hellman Keys) to create a new key, or by calling CryptGetUserKey to retrieve an existing one.
  3. Create a D-H public-key blob by calling CryptExportKey, passing PRIVATEKEYBLOB in the dwBlobType parameter and the handle to the D-H key in the hKey parameter.
  4. When finished with the key, call CryptDestroyKey to destroy the handle (HCRYPTKEY) to the key.