4

I am trying to create x-pkcs7-signature s/mime messages in C#. I've been experimenting with Mimekit and can only make pkcs7 messages.

Does anyone know what I need to do to create x-pkcs messages or point me to some examples?

Regards

Ace Grace
  • 631
  • 1
  • 7
  • 21
  • FWIW, `application/x-pkcs7-mime` and `application/x-pkcs7-signature` were used before S/MIME became a standard back in the 90's. The official mime-types are now (and have been for over 2 decades) `application/pkcs7-mime` and `application/pkcs7-signature`. – jstedfast Dec 19 '17 at 21:48

1 Answers1

0

There are 2 different ways to sign a message using S/MIME:

  1. application/[x-]pkcs7-mime; smime-type=signed-data
  2. application/[x-]pkcs7-signature

To sign the first way, do this:

var signer = new MailboxAddress ("", "signer@example.com");
var signed = ApplicationPkcs7Mime.Sign (signer, DigestAlgorithm.Sha256, entity);

The other way is done like this:

using (var ctx = new WindowsSecureMimeContext ()) {
    var signer = new MailboxAddress ("", "signer@example.com");
    var signed = MultipartSigned.Sign (ctx, signer, DigestAlgorithm.Sha256, entity);
}

In both cases, you can also use a MimeKit.Cryptography.CmsSigner instead of a MailboxAddress. You could also use a SecureMailboxAddress if you know the fingerprint of the certificate.

jstedfast
  • 35,744
  • 5
  • 97
  • 110