Using the CryptEncryptMessage Function and Associated Structures

CryptEncryptMessage, is the only function call necessary to accomplish all of the tasks listed in the previous section. Here again, initialization of structures and other data is necessary first. The following illustration shows the relationship between those function parameters that point to structures or arrays and their initialized data.

    To encrypt data
  1. Get a pointer to the content to be encrypted.
  2. Get the size of the content to be encrypted.
  3. Get a handle on a cryptographic provider.
  4. Open a certificate store.
  5. Get the recipient certificate.
  6. Create the "recipient cert" array.
  7. Initialize the CRYPT_ALGORITHM_IDENTIFIER structure.
  8. Initialize the CRYPT_ENCRYPT_MESSAGE_PARA structure.
  9. Call CryptEncryptMessage to encrypt the content and create a digitally enveloped message.