C# 创建 MIME 消息?

发布于 2024-09-09 15:59:38 字数 222 浏览 6 评论 0原文

C# .Net 中是否有内置的 MIME 文件功能?我想要做的是:

  1. 将文件转换为 MIME 消息
  2. 将 MIME 消息签名为 pkcs 7 blob
  3. 的 pcks 7 blob MIME
  4. 最后加密整个内容。

关于如何解决这个问题有什么建议吗(不是加密或签名部分,而是 MIMEing)? MIME 处理文件到底涉及什么?

Is there any built in functionality to MIME a file in C# .Net? What I am looking to do is:

  1. Convert a file into a MIME message
  2. Sign the MIME Message to a pcks 7 blob
  3. MIME that pkcs 7 blob
  4. Finally encrypt the entire thing.

Any suggestions on how I would go about this (not the encryption or signing part but the MIMEing)? What exactly is envolved in MIMEing a file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

丶视觉 2024-09-16 15:59:38

有一个很好的商业包,只需支付少量费用:
Mime4Net

There is a good commercial package for a small fee:
Mime4Net

丢了幸福的猪 2024-09-16 15:59:38

我建议您不要使用第三方库,而是查看核心 .NET 库。使用 Attachment 类;它自 .NET 2 以来就已存在。

Rather than deal with third party libraries, I suggest you look to the core .NET library. Use the Attachment class; it's been around since .NET 2.

暗地喜欢 2024-09-16 15:59:38

据我所知,裸露的.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) 

代码取自 S/MIME 教程页面)

As far as I know there is no such support in the bare .NET. You have to try one of third party libraries. One of them is our Rebex Secure Mail for .NET. Following code shows how to achieve it:

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) 

(Code taken from the S/MIME tutorial page)

走过海棠暮 2024-09-16 15:59:38

没有提到的是 MimeKit
它可以完成您需要它做的一切。

(这仍然是谷歌的热门,所以我想添加这个宝石)

Something that hasn't been mentioned is MimeKit.
It does everything that you need it to do.

(this is still a top hit in google so thought I'd add this gem)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文