Private Key Programming Examples

Question:

I downloaded and installed the S/MIME .Net Component. I then downloaded the Decrypt sample and tried to execute the sample application. When the application reaches the following lines:

                   // Get the first encrypting certificate.
                  // In complex cases where the MIME is nested and contains
                  // other encrypted MIME messages, there will be more than
                  // one encrypting certificate.
                  Chilkat.Cert cert;
                  cert = mime.GetEncryptCert(0);
                  listBox1.Items.Add("Encrypted By: " + cert.SubjectDN);
The following error occurs: NullReference When looking into the locals the cert variable is null so I assume the mime.GetEncryptCert(0) did not work.

Answer:

In any of the Chilkat examples which require a private key, it will be necessary to modify the examples to use your own data and certificates. In the case of the S/MIME decryption example, you will first need to run the S/MIME encryption example to create an encrypted MIME message using your certificate, and then use this with the S/MIME decryption example. (Private keys are required for public-key decryption, and creating digital signatures. Only public-keys are needed for public-key encryption, or verifying digital signatures.)