• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Encrypt Message

Encrypts a MIME message with S/MIME.

Code

using System.Security.Cryptography.X509Certificates;
using DRIT.Mail.Rfc.Mime;
using DRIT.Mail.Rfc.SMime;

MimeMessage message = MimeMessage.Load("message.eml");

// Load the recipient's public certificate
var certificate = new X509Certificate2("recipient.cer");

var options = new SMimeEncryptionOptions
{
    EncryptionAlgorithm = SMimeEncryptionAlgorithm.Aes256Cbc,
};
options.Recipients.Add(certificate);

var encryptor = new SMimeEncryptor(options);
MimeMessage encrypted = encryptor.Encrypt(message);

encrypted.Write("encrypted.eml");

Remarks

SMimeEncryptor produces an application/pkcs7-mime enveloped message as defined in RFC 5751. One or more recipient certificates can be added; each recipient can decrypt the message with their private key.

  • Improve this Doc
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX