Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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 = "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) 

(Code taken from the S/MIME tutorial page)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top