S/MIME libraries for .net?

By : Gabriel
Source: Stackoverflow.com

I need to create S/MIME messages using C# (as specified in RFC 2633, "S/MIME Version 3 message specification", and RFC 3335). The only S/MIME library I can find is a commercial library (http://www.example-code.com/csharp/smime.asp), which is no good for us.

Are there any existing libraries to accomplish creating S/MIME messages, and in particular, .p7s files?

I have all the encrypted and signed elements that need to go into this file, but I'd like to create the .p7s file without handrolling my own library with the aid of the RFC document...

EDIT: I've found another commercial S/MIME library, which is still no good for our requirements. It's looking more and more like I'm going to have to hand roll a S/MIME library, which is sad. Is everyone in .net who needs S/MIME using commercial, closed source libraries to do it?

By : Gabriel


I've written my own MIME library with support for S/MIME called MimeKit which is far more robust than anything based on System.Net.Mail which is horrendously broken.

It supports raw 8bit headers, rfc822 group addresses, scraping names out of rfc822 comments in address headers (To/Ccc/Bcc/etc), parsing mbox formatted message spools (including support for the Content-Length-based SunOS format) and it's an order of magnitude faster than any other C# MIME parser out there because it is byte-stream based instead of TextReader-based (which is also how it supports raw 8bit headers much better than any other C# parser).

By : jstedfast

I spent a lot of time looking for a good S/MIME library for .NET, with no luck. I ended up creating my own, called OpaqueMail.

It's open source and completely free. It inherits from the System.Net.Mail.SmtpClient class, so porting existing code is straightforward. It also includes classes for working with POP3 and IMAP.

Check it out at http://opaquemail.org/.

An example of sending a S/MIME triple-wrapped message (which is digitally signed, encrypted, then digitally signed again) is:

// Instantiate a new SMTP connection to Gmail using TLS/SSL protection.
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.Credentials = new NetworkCredential("[email protected]", "[email protected]");
smtpClient.EnableSsl = true;

// Create a new MailMessage class with lorem ipsum.
MailMessage message = new MailMessage("[email protected]", "[email protected]", "Example subject", "Lorem ipsum body.");

// Specify that the message should be signed, have its envelope encrypted, and then be signed again (triple-wrapped).
message.SmimeSigned = true;
message.SmimeEncryptedEnvelope = true;
message.SmimeTripleWrapped = true;

// Specify that the message should be timestamped.
message.SmimeSigningOptionFlags = SmimeSigningOptionFlags.SignTime;

// Load the signing certificate from the Local Machine store.            
message.SmimeSigningCertificate = CertHelper.GetCertificateBySubjectName(StoreLocation.LocalMachine, "[email protected]");

// Send the message.
await smtpClient.SendAsync(message);

Hope this helps.

It's quite hard to implement complete s/mime as it requires lots of extra work. You can use SMIME components in SecureBlackbox for your task.

Update: SecureBlackbox is our product. It completely supports Silverlight and Windows Phone (including Mango).

This video can help you solving your question :)
By: admin