Chilkat:如何解密加密的电子邮件?
我使用 Chilkat .NET 4 发送了一封电子邮件。该电子邮件使用 .pfx 文件进行签名,并使用收件人的 .cer 文件进行加密。这2个文件存储在Certificates mmc的“Trusted People”文件夹中。
现在我尝试接收&使用 Chilkat 解密此电子邮件。它有效,但电子邮件未解密。我的 .pfx 文件和发件人的 .cer 文件始终位于“受信任的人”文件夹中。我尝试使用 AddPfxSourceData 方法添加我自己的私有证书,它返回 TRUE 但没有任何反应。我使用的所有 Chilkat 对象的 LastErrorText 属性中没有任何错误。
这是我的代码(mail.Decrypted 始终为 FALSE):
MailMan pop3 = new Chilkat.MailMan();
pop3.UnlockComponent("30-day trial");
pop3.MailHost = "pop.server.net";
pop3.MailPort = 110;
pop3.PopUsername = "[email protected]";
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");
}
有什么想法吗?
更新:我用来发送加密电子邮件的代码:
Chilkat.MailMan mailman = new Chilkat.MailMan();
mailman.UnlockComponent("30-day trial");
mailman.SmtpHost = "smtp.server.net";
mailman.SmtpUsername = "[email protected]";
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 = "[email protected]";
email.AddTo("My Recipient", "[email protected]");
// Certificate of [email protected]
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 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 = "[email protected]";
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 = "[email protected]";
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 = "[email protected]";
email.AddTo("My Recipient", "[email protected]");
// Certificate of [email protected]
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 !");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最后用两台不同的计算机尝试了这个场景,一台用于发送者,一台用于接收者,并且它有效。我认为这是因为我用于发送方和发送方的两个 .pfx 文件。收件人是自动生成的在同一台电脑上自动签名...
我在每台电脑上生成了一个新的 .pfx 文件,效果很好:)
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 :)