2010-07-16 49 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)