2010-07-16 105 views
3

在C#.Net中是否有任何内置函数来MIME文件?我所希望做的是:C#创建MIME消息?

  1. 将文件转换成一个MIME消息
  2. 注册的MIME信息的PCKS 7 BLOB
  3. MIME是PKCS 7 BLOB
  4. 最后加密整个事情。

关于如何去解决这个问题(而不是加密或签名部分,但MIMEing)的任何建议?包含在MIMEing文件中的究竟是什么?

回答

2

有一个很好的商业包装一小笔费用: Mime4Net

+0

(从S/MIME tutorial page采取代号)如果皮蒂接受这个答案,我会奖励赏金。我的猜测是商业包装不会是我们想要的,但我不会为Petey说话。就我个人而言,我会走这条路去获得我认为有用的东西。 – Tergiver 2010-07-26 22:36:55

+0

我最终编写了自己的MIME解析器。但我会接受这一点。 – 2010-07-27 14:46:05

+0

“小”IFF你不想要来源。 – jeff7091 2013-10-11 06:05:26

2

而不是处理第三方库,我建议你看看核心.NET库。使用Attachment类;它一直在.NET 2以上。

+0

是否可以从System.Net.Mail类中提取MIME编码的消息而不发送它? – Rup 2010-07-26 18:20:48

+0

@优惠:优点。答案当然不是。至少,不是没有挖掘到内部MailWriter类。我显然误解了这个问题。如果他想将MIME附件作为电子邮件的一部分进行签名和加密,则只需在将内容传递给附件之前对其进行签名和加密即可。 – Randolpho 2010-07-26 18:43:19

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 = "[email protected]"; 
message.To = "[email protected]"; 
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)