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
-
Get a pointer to the content to be encrypted.
-
Get the size of the content to be encrypted.
-
Get a handle on a cryptographic provider.
-
Open a certificate store.
-
Get the recipient certificate.
-
Create the "recipient cert" array.
-
Initialize the CRYPT_ALGORITHM_IDENTIFIER structure.
-
Initialize the CRYPT_ENCRYPT_MESSAGE_PARA structure.
-
Call CryptEncryptMessage to encrypt the content and create a digitally enveloped message.