【问题标题】:C# Create MIME Message?C# 创建 MIME 消息?
【发布时间】:2011-03-17 02:32:17
【问题描述】:

在 C# .Net 中是否有任何内置功能可以 MIME 文件?我要做的是:

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

关于我将如何处理这件事的任何建议(不是加密或签名部分,而是 MIMEing)? MIME 文件的具体内容是什么?

【问题讨论】:

    标签: c# mime pkcs#7


    【解决方案1】:

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

    【讨论】:

    • 如果 Petey 接受这个答案,我将奖励赏金。我的猜测是商业包不会是我们想要的,但我不能代表 Petey。就我个人而言,我会走这条路来获得一些我相信会奏效的东西。
    • “小”IFF 你不想要源代码。
    【解决方案2】:

    与其处理第三方库,我建议您查看核心 .NET 库。使用Attachment 类;它从 .NET 2 开始就存在了。

    【讨论】:

    • 是否可以从 System.Net.Mail 类中提取 MIME 编码的消息而不发送它?
    • @Rup:好点。答案当然是否定的。至少,不是不深入研究内部 MailWriter 类。我显然误读了这个问题;如果他想对作为电子邮件的一部分的 MIME 附件进行签名和加密,就像在将内容传递给附件之前对其进行签名和加密一样简单。
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2013-06-07
      • 2023-03-22
      • 2020-12-31
      • 2016-03-11
      • 2016-06-26
      • 2018-06-01
      • 2012-11-18
      • 2013-02-09
      • 2013-07-12
      相关资源
      最近更新 更多