Exporting a Diffie-Hellman Private (secret) Key

The steps necessary are shown in the following procedure.

    To export a D-H private key
  1. Get a handle to a D-H provider.
  2. Get a handle to a D-H key. This can be done 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.