Пример #1
0
        private Multipart Encrypt(Multipart input, GpgPublicKeyInfo recipientKey)
        {
            var gpgMultipart = new Multipart("encrypted");

            gpgMultipart.ContentType.Parameters.Add("protocol", "application/pgp-encrypted");

            var versionPart = new TextPart("pgp-encrypted");

            versionPart.ContentType.MediaType = "application";
            versionPart.Headers.Add(new Header("Content-Description", "PGP/MIME version identification"));
            versionPart.Text = "Version: 1";
            gpgMultipart.Add(versionPart);

            var multipartStream = new MemoryStream();

            input.WriteTo(multipartStream);
            multipartStream.Position = 0;
            var plainText = Encoding.UTF8.GetString(multipartStream.ToArray()).Replace("\n", "\r\n");

            _gpg.Encrypt(plainText, out string cipherText, recipientKey.Id, true);
            var encryptedPart = new TextPart("octet-stream");

            encryptedPart.ContentType.MediaType       = "application";
            encryptedPart.ContentType.Name            = "encrypted.asc";
            encryptedPart.ContentDisposition          = new ContentDisposition("inline");
            encryptedPart.ContentDisposition.FileName = "encrypted.asc";
            encryptedPart.Text = cipherText;
            encryptedPart.ContentTransferEncoding = ContentEncoding.SevenBit;
            encryptedPart.Headers.Remove(HeaderId.ContentTransferEncoding);
            gpgMultipart.Add(encryptedPart);

            return(gpgMultipart);
        }
Пример #2
0
        public MimeMessage Create(InternetAddress from, InternetAddress to, GpgPrivateKeyInfo senderKey, GpgPublicKeyInfo recipientKey, string subject, Multipart content)
        {
            if (senderKey != null && recipientKey != null)
            {
                content = EncryptAndSign(content, senderKey, recipientKey);
            }
            else if (recipientKey != null)
            {
                content = Encrypt(content, recipientKey);
            }
            else if (senderKey != null)
            {
                content = Sign(content, senderKey);
            }

            var message = new MimeMessage();

            message.From.Add(from);
            message.To.Add(to);
            message.Subject = subject;
            message.Body    = content;

            return(message);
        }
Пример #3
0
 public void Send(InternetAddress from, InternetAddress to, GpgPrivateKeyInfo senderKey, GpgPublicKeyInfo recipientKey, string subject, Multipart content)
 {
     Send(Create(from, to, senderKey, recipientKey, subject, content));
 }
Пример #4
0
 public void Send(InternetAddress to, GpgPrivateKeyInfo senderKey, GpgPublicKeyInfo recipientKey, string subject, Multipart content)
 {
     Send(MailboxAddress.Parse(_config.SystemMailAddress), to, senderKey, recipientKey, subject, content);
 }