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 !");
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:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.