public Encrypt ( MimeKit.Cryptography.CryptographyContext ctx ) : void | ||
ctx | MimeKit.Cryptography.CryptographyContext | The cryptography context. |
return | void |
public void TestMimeMessageEncrypt () { var body = new TextPart ("plain") { Text = "This is some cleartext that we'll end up encrypting..." }; var self = new SecureMailboxAddress ("MimeKit UnitTests", "*****@*****.**", "44CD48EEC90D8849961F36BA50DCD107AB0821A2"); var message = new MimeMessage { Subject = "Test of signing with OpenPGP" }; message.From.Add (self); message.To.Add (self); message.Body = body; using (var ctx = new DummyOpenPgpContext ()) { message.Encrypt (ctx); Assert.IsInstanceOf<MultipartEncrypted> (message.Body); var encrypted = (MultipartEncrypted) message.Body; //using (var file = File.Create ("pgp-encrypted.asc")) // encrypted.WriteTo (file); var decrypted = encrypted.Decrypt (ctx); Assert.IsInstanceOf<TextPart> (decrypted, "Decrypted part is not the expected type."); Assert.AreEqual (body.Text, ((TextPart) decrypted).Text, "Decrypted content is not the same as the original."); } }
public void TestSecureMimeEncryption () { var body = new TextPart ("plain") { Text = "This is some cleartext that we'll end up encrypting..." }; var self = new MailboxAddress ("MimeKit UnitTests", "*****@*****.**"); var message = new MimeMessage { Subject = "Test of encrypting with S/MIME" }; message.From.Add (self); message.To.Add (self); message.Body = body; using (var ctx = CreateContext ()) { message.Encrypt (ctx); Assert.IsInstanceOf<ApplicationPkcs7Mime> (message.Body, "The message body should be an application/pkcs7-mime part."); var encrypted = (ApplicationPkcs7Mime) message.Body; Assert.AreEqual (SecureMimeType.EnvelopedData, encrypted.SecureMimeType, "S/MIME type did not match."); var decrypted = encrypted.Decrypt (ctx); Assert.IsInstanceOf<TextPart> (decrypted, "Decrypted part is not the expected type."); Assert.AreEqual (body.Text, ((TextPart) decrypted).Text, "Decrypted content is not the same as the original."); } }