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
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
There are 2 different ways to sign a message using S/MIME:
application/[x-]pkcs7-mime; smime-type=signed-data
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.