【发布时间】:2011-03-17 02:32:17
【问题描述】:
在 C# .Net 中是否有任何内置功能可以 MIME 文件?我要做的是:
- 将文件转换为 MIME 消息
- 将 MIME 消息签名到 pcks 7 blob
- pkcs 7 blob 的 MIME
- 最后加密整个东西。
关于我将如何处理这件事的任何建议(不是加密或签名部分,而是 MIMEing)? MIME 文件的具体内容是什么?
【问题讨论】:
在 C# .Net 中是否有任何内置功能可以 MIME 文件?我要做的是:
关于我将如何处理这件事的任何建议(不是加密或签名部分,而是 MIMEing)? MIME 文件的具体内容是什么?
【问题讨论】:
有一个很好的商业套餐,只需支付少量费用: Mime4Net
【讨论】:
与其处理第三方库,我建议您查看核心 .NET 库。使用Attachment 类;它从 .NET 2 开始就存在了。
【讨论】:
据我所知,裸露的 .NET 中没有这样的支持。您必须尝试第三方库之一。其中之一是我们的Rebex Secure Mail for .NET。下面的代码展示了如何实现它:
using Rebex.Mail;
using Rebex.Mime.Headers;
using Rebex.Security.Certificates;
...
// load the sender's certificate and
// associated private key from a file
Certificate signer = Certificate.LoadPfx("hugo.pfx", "password");
// load the recipient's certificate
Certificate recipient = Certificate.LoadDer("joe.cer");
// create an instance of MailMessage
MailMessage message = new MailMessage();
// set its properties to desired values
message.From = "hugo@example.com";
message.To = "joe@example.com";
message.Subject = "This is a simple message";
message.BodyText = "Hello, Joe!";
message.BodyHtml = "Hello, <b>Joe</b>!";
// sign the message using Hugo's certificate
message.Sign(signer);
// and encrypt it using Joe's certificate
message.Encrypt(recipient);
// if you wanted Hugo to be able to read the message later as well,
// you can encrypt it for Hugo as well instead - comment out the previous
// encrypt and uncomment this one:
// message.Encrypt(recipient, signer)
(代码取自S/MIME tutorial page)
【讨论】: