2

I sent an email message using Chilkat .NET 4. This email is signed with a .pfx file and encrypted with the .cer file of the recipient. These 2 files are stored in the "Trusted People" folder in Certificates mmc.

Now I try to receive & decrypt this email with Chilkat. It works but the email is not decrypted. My .pfx file and the .cer file of the sender are always in the "Trusted People" folder. I tried to add my own private certificate with AddPfxSourceData method, it returns TRUE but nothing happens. There aren't any errors in LastErrorText property of all Chilkat objects that i used.

This is my code (mail.Decrypted is always FALSE) :

            MailMan pop3 = new Chilkat.MailMan();
            pop3.UnlockComponent("30-day trial");

            pop3.MailHost = "pop.server.net";
            pop3.MailPort = 110;

            pop3.PopUsername = "my@email.com";
            pop3.PopPassword = "mypassword";

            bool succes = pop3.AddPfxSourceFile("C:\\my_pfx.pfx, "mypfxpassword");

            EmailBundle emailBundle = pop3.CopyMail();

            for (int i = 0; i < emailBundle.MessageCount; i++)
            {
                Email mail = emailBundle.GetEmail(i);

                if(mail.ReceivedEncrypted && mail.Decrypted)
                    Console.WriteLine(mail.Body);
                else
                    Console.WriteLine("Cannot decrypt this mail");
            }

Any ideas ?

UPDATED : The code that i used to send the encrypted email :

            Chilkat.MailMan mailman = new Chilkat.MailMan();
            mailman.UnlockComponent("30-day trial");

            mailman.SmtpHost = "smtp.server.net";

            mailman.SmtpUsername = "sender@mail.com";
            mailman.SmtpPassword = "senderpassword";

            Chilkat.Email email = new Chilkat.Email();

            email.Subject = "This is an encrypted email !";
            email.Body = "This is the content of a digitally encrypted mail !";

            email.From = "sender@mail.com";
            email.AddTo("My Recipient", "my@email.com");

            // Certificate of my@email.com
            Chilkat.Cert recipientCert = new Chilkat.Cert();
            recipientCert.LoadFromFile("C:\\recipient_cert.cer");

            email.SetEncryptCert(recipientCert);
            email.SendEncrypted = true;

            bool success = mailman.SendEmail(email);

            if (success)
                Console.WriteLine("Mail sent !");
Nico
  • 575
  • 3
  • 8
  • 19
  • 1
    Is `mail.ReceivedEncrypted` true? – GalacticCowboy Jul 09 '11 at 19:24
  • yes, mail.ReceivedEncrypted is TRUE. In fact, i learnt that Chilkat tries to decrypt automatically the email, i think my problem concerns the location of my certificates. Maybe that Chilkat cannot retrieve my certificates... – Nico Jul 11 '11 at 09:15

1 Answers1

1

I finally try this scenario with 2 differents computer, one for the sender and one for the recipient, and it works. I think it was because the two .pfx files that i used for the sender & the recipient were been auto-generated & auto-signed on the same pc... I generated a new .pfx file on each pc and it works great :)

Nico
  • 575
  • 3
  • 8
  • 19