/* * Only encrypts the given MimeEntity. */ private MultipartEncrypted EncryptEntity(Node entityNode, MimeEntity entity) { // Retrieving node that declares encryption settings for us. var encryptionNode = entityNode ["encrypt"]; // Retrieving MailboxAddresses to encrypt message for. var receivers = GetReceiversMailboxAddress(encryptionNode); // Creating our Gnu Privacy Guard context. // Notice, no password necessary when doing encryption, since we're only using public certificates. using (var ctx = new GnuPrivacyContext()) { // Encrypting content of email and returning to caller. var retVal = MultipartEncrypted.Encrypt( ctx, receivers, entity); // Setting preamble and epilogue AFTER encryption, to give opportunity to give hints to receiver. retVal.Preamble = entityNode.GetChildValue <string> ("preamble", _context, null); retVal.Epilogue = entityNode.GetChildValue <string> ("epilogue", _context, null); // Returning encrypted Multipart. return(retVal); } }
public void TestMultipartEncryptedEncryptAlgorithmUsingKeys() { var body = new TextPart("plain") { Text = "This is some cleartext that we'll end up encrypting..." }; var self = new MailboxAddress("MimeKit UnitTests", "*****@*****.**"); IList <PgpPublicKey> recipients; using (var ctx = new DummyOpenPgpContext()) { recipients = ctx.GetPublicKeys(new [] { self }); } foreach (EncryptionAlgorithm algorithm in Enum.GetValues(typeof(EncryptionAlgorithm))) { if (algorithm == EncryptionAlgorithm.RC240 || algorithm == EncryptionAlgorithm.RC264 || algorithm == EncryptionAlgorithm.RC2128) { continue; } var encrypted = MultipartEncrypted.Encrypt(algorithm, recipients, body); //using (var file = File.Create ("pgp-encrypted.asc")) // encrypted.WriteTo (file); var decrypted = encrypted.Decrypt(); 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 TestMultipartEncryptedSignAndEncryptAlgorithm() { var body = new TextPart("plain") { Text = "This is some cleartext that we'll end up signing and encrypting..." }; var self = new SecureMailboxAddress("MimeKit UnitTests", "*****@*****.**", "AB0821A2"); DigitalSignatureCollection signatures; var encrypted = MultipartEncrypted.SignAndEncrypt(self, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, new [] { self }, body); //using (var file = File.Create ("pgp-signed-encrypted.asc")) // encrypted.WriteTo (file); var decrypted = encrypted.Decrypt(out signatures); 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."); Assert.AreEqual(1, signatures.Count, "Verify returned an unexpected number of signatures."); foreach (var signature in signatures) { try { bool valid = signature.Verify(); Assert.IsTrue(valid, "Bad signature from {0}", signature.SignerCertificate.Email); } catch (DigitalSignatureVerifyException ex) { Assert.Fail("Failed to verify signature: {0}", ex); } } }
/* * Processes an encrypted Multipart. */ private void ProcessEncryptedMultipart(MultipartEncrypted encryptedMultipart, Node entityNode) { try { // Creating cryptographic context. using (var ctx = new GnuPrivacyContext()) { // Associating our KeyPasswordMapper collection with GnuPG CryptographyContext. ctx.Passwords = _passwords; // Decrypting entity, making sure we retrieve signatures at the same time, if there are any. DigitalSignatureCollection signatures; var decryptedMultipart = encryptedMultipart.Decrypt(ctx, out signatures); // Making sure caller gets notified of which private key was used for decrypting encrypted multipart. entityNode.Add("decryption-key", ctx.LastUsedUserId); // Adding signatures. ProcessSignatures(entityNode, signatures); // Parsing decrypted result. ProcessEntity(decryptedMultipart, entityNode); } } catch (Exception err) { // Couldn't decrypt Multipart, returning raw encrypted content. entityNode.Add("processing-message", err.Message); foreach (var idxEntity in encryptedMultipart) { ProcessEntity(idxEntity, entityNode); } } }
/* * Only encrypts the given MimeEntity. */ MultipartEncrypted EncryptEntity(Node entityNode, MimeEntity entity) { // Retrieving node that declares encryption settings for us. var encryptionNode = entityNode ["encrypt"]; // Retrieving MailboxAddresses to encrypt message for. var receivers = GetReceiversMailboxAddress(encryptionNode); /* * Creating our PGP context. * Notice, the password is not necessary when doing encryption, since we're only using public keys. */ using (var ctx = _context.RaiseEvent( ".p5.crypto.pgp-keys.context.create", new Node("", false)).Get <OpenPgpContext> (_context)) { // Encrypting content of email and returning to caller. var retVal = MultipartEncrypted.Encrypt( ctx, receivers, entity); // Returning encrypted Multipart. return(retVal); } }
public void Encrypt(MimeMessage message) { // encrypt our message body using our custom GnuPG cryptography context using (var ctx = new MyGnuPGContext()) { // Note: this assumes that each of the recipients has a PGP key associated // with their email address in the user's public keyring. // // If this is not the case, you can use SecureMailboxAddresses instead of // normal MailboxAddresses which would allow you to specify the fingerprint // of their PGP keys. You could also choose to use one of the Encrypt() // overloads that take a list of PgpPublicKeys. message.Body = MultipartEncrypted.Encrypt(ctx, message.To.Mailboxes, message.Body); } }
public void TestMultipartEncryptedEncrypt() { var body = new TextPart("plain") { Text = "This is some cleartext that we'll end up encrypting..." }; var self = new MailboxAddress("MimeKit UnitTests", "*****@*****.**"); var encrypted = MultipartEncrypted.Encrypt(new [] { self }, body); //using (var file = File.Create ("pgp-encrypted.asc")) // encrypted.WriteTo (file); var decrypted = encrypted.Decrypt(); 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."); }
/* * Signs and encrypts the given MimeEntity. */ MultipartEncrypted SignAndEncryptEntity(Node entityNode, MimeEntity entity) { // Retrieving [sign] and [encrypt] nodes. var signatureNode = entityNode ["sign"]; var encryptionNode = entityNode ["encrypt"]; // Getting signature email as provided by caller. var signatureAddress = GetSignatureMailboxAddress(signatureNode); // Retrieving MailboxAddresses to encrypt message for. var receivers = GetReceiversMailboxAddress(encryptionNode); /* * Figuring out signature Digest Algorithm to use for signature, defaulting to SHA256. * SHA256 should be safe, since there are no known collision weaknesses in it. * Therefor we default to SHA256, unlesss caller explicitly tells us he wants to use another algorithm. */ var algo = signatureNode.GetChildValue("digest-algorithm", _context, DigestAlgorithm.Sha256); /* * Creating our Gnu Privacy Guard context, passing in password to retrieve private signing key. */ using (var ctx = _context.RaiseEvent( ".p5.crypto.pgp-keys.context.create", new Node("", false, new Node [] { new Node("password", signatureAddress.Item1), new Node("fingerprint", signatureNode.GetExChildValue <string> ("fingerprint", _context, null) ?? _context.RaiseEvent("p5.auth.pgp.get-fingerprint").Get <string> (_context)) })) .Get <OpenPgpContext> (_context)) { // Signing and Encrypting content of email. var retVal = MultipartEncrypted.SignAndEncrypt( ctx, signatureAddress.Item2, algo, receivers, entity); // Returning encrypted Multipart. return(retVal); } }
/* * Cryptographically signs and encrypts an entity. */ static MultipartEncrypted SignAndEncrypt( MimeEntity entity, Node encryptionNode, string armoredPrivateKey, string keyPassword) { var algo = DigestAlgorithm.Sha256; using (var ctx = new CreatePgpMimeContext { Password = keyPassword }) { return(MultipartEncrypted.SignAndEncrypt( ctx, PgpHelpers.GetSecretKeyFromAsciiArmored(armoredPrivateKey), algo, GetEncryptionKeys(encryptionNode), entity)); } }
/* * Processes an encrypted multipart. */ void ProcessEncryptedMultipart(MultipartEncrypted encryptedMultipart, Node entityNode) { // Creating cryptography context. using (var ctx = _context.RaiseEvent( ".p5.crypto.pgp-keys.context.create", new Node("", false, new Node [] { new Node("password", _password), new Node("fingerprint", _fingerprint) })) .Get <OpenPgpContext> (_context)) { // Decrypting entity, making sure we retrieve signatures at the same time, if there are any. DigitalSignatureCollection signatures; var decryptedMultipart = encryptedMultipart.Decrypt(ctx, out signatures); // Adding signatures. ProcessSignatures(entityNode, signatures); // Parsing decrypted result. ProcessEntity(decryptedMultipart, entityNode); } }
/* * Signs and encrypts the given MimeEntity. */ private MultipartEncrypted SignAndEncryptEntity( Node entityNode, MimeEntity entity) { // Retrieving [sign] and [encrypt] nodes. var signatureNode = entityNode ["sign"]; var encryptionNode = entityNode ["encrypt"]; // Getting signature email as provided by caller. var signatureAddress = GetSignatureMailboxAddress(signatureNode); // Retrieving MailboxAddresses to encrypt message for. var receivers = GetReceiversMailboxAddress(encryptionNode); // Figuring out signature Digest Algorithm to use for signature, defaulting to Sha256. var algo = signatureNode.GetChildValue("digest-algorithm", _context, DigestAlgorithm.Sha256); // Creating our Gnu Privacy Guard context. using (var ctx = new GnuPrivacyContext()) { // Setting password to retrieve signing certificate from GnuPG context. ctx.Password = signatureAddress.Item1; // Signing and Encrypting content of email. var retVal = MultipartEncrypted.SignAndEncrypt( ctx, signatureAddress.Item2, algo, receivers, entity); // Setting preamble and epilogue AFTER encryption, to give opportunity to give receiver hints. retVal.Preamble = entityNode.GetChildValue <string> ("preamble", _context, null); retVal.Epilogue = entityNode.GetChildValue <string> ("epilogue", _context, null); // Returning encrypted Multipart. return(retVal); } }
public void TestPgpMimeSignAndEncrypt() { var self = new MailboxAddress("MimeKit UnitTests", "*****@*****.**"); var recipients = new List <MailboxAddress> (); // encrypt to ourselves... recipients.Add(self); var cleartext = new TextPart("plain"); cleartext.Text = "This is some cleartext that we'll end up encrypting..."; using (var ctx = new DummyOpenPgpContext()) { var encrypted = MultipartEncrypted.Create(ctx, self, DigestAlgorithm.Sha1, recipients, cleartext); //using (var file = File.Create ("pgp-signed-encrypted.asc")) // encrypted.WriteTo (file); DigitalSignatureCollection signatures; var decrypted = encrypted.Decrypt(ctx, out signatures); Assert.IsInstanceOfType(typeof(TextPart), decrypted, "Decrypted part is not the expected type."); Assert.AreEqual(cleartext.Text, ((TextPart)decrypted).Text, "Decrypted content is not the same as the original."); Assert.AreEqual(1, signatures.Count, "Verify returned an unexpected number of signatures."); foreach (var signature in signatures) { try { bool valid = signature.Verify(); Assert.IsTrue(valid, "Bad signature from {0}", signature.SignerCertificate.Email); } catch (DigitalSignatureVerifyException ex) { Assert.Fail("Failed to verify signature: {0}", ex); } } } }
public void TestPgpMimeEncryption() { var self = new MailboxAddress("MimeKit UnitTests", "*****@*****.**"); var recipients = new List <MailboxAddress> (); // encrypt to ourselves... recipients.Add(self); var cleartext = new TextPart("plain"); cleartext.Text = "This is some cleartext that we'll end up encrypting..."; using (var ctx = new DummyOpenPgpContext()) { var encrypted = MultipartEncrypted.Create(ctx, recipients, cleartext); //using (var file = File.Create ("pgp-encrypted.asc")) // encrypted.WriteTo (file); var decrypted = encrypted.Decrypt(ctx); Assert.IsInstanceOfType(typeof(TextPart), decrypted, "Decrypted part is not the expected type."); Assert.AreEqual(cleartext.Text, ((TextPart)decrypted).Text, "Decrypted content is not the same as the original."); } }
protected internal override void VisitMultipartEncrypted(MultipartEncrypted encrypted) { MultipartEncrypted++; base.VisitMultipartEncrypted(encrypted); }
public void TestArgumentExceptions() { Assert.Throws <ArgumentNullException> (() => CryptographyContext.Create(null)); Assert.Throws <ArgumentNullException> (() => CryptographyContext.Register((Type)null)); Assert.Throws <ArgumentNullException> (() => CryptographyContext.Register((Func <OpenPgpContext>)null)); Assert.Throws <ArgumentNullException> (() => CryptographyContext.Register((Func <SecureMimeContext>)null)); using (var ctx = new DummyOpenPgpContext()) { var mailboxes = new [] { new MailboxAddress("MimeKit UnitTests", "*****@*****.**") }; var emptyMailboxes = new MailboxAddress[0]; var pubkeys = ctx.GetPublicKeys(mailboxes); var key = ctx.GetSigningKey(mailboxes[0]); var emptyPubkeys = new PgpPublicKey[0]; DigitalSignatureCollection signatures; var stream = new MemoryStream(); var entity = new MimePart(); Assert.Throws <ArgumentException> (() => ctx.KeyServer = new Uri("relative/uri", UriKind.Relative)); Assert.Throws <ArgumentNullException> (() => ctx.GetDigestAlgorithm(null)); Assert.Throws <ArgumentOutOfRangeException> (() => ctx.GetDigestAlgorithmName(DigestAlgorithm.DoubleSha)); Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.DoubleSha)); Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.Tiger192)); Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.Haval5160)); Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.MD4)); Assert.Throws <ArgumentOutOfRangeException> (() => OpenPgpContext.GetDigestAlgorithm((Org.BouncyCastle.Bcpg.HashAlgorithmTag) 1024)); Assert.Throws <ArgumentNullException> (() => new ApplicationPgpEncrypted((MimeEntityConstructorArgs)null)); Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature((MimeEntityConstructorArgs)null)); Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature((Stream)null)); // Accept Assert.Throws <ArgumentNullException> (() => new ApplicationPgpEncrypted().Accept(null)); Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature(stream).Accept(null)); // Decrypt Assert.Throws <ArgumentNullException> (() => ctx.Decrypt(null), "Decrypt"); // Encrypt Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, (MailboxAddress[])null, stream), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, stream), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt((MailboxAddress[])null, stream), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt((PgpPublicKey[])null, stream), "Encrypt"); Assert.Throws <ArgumentException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "Encrypt"); Assert.Throws <ArgumentException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "Encrypt"); Assert.Throws <ArgumentException> (() => ctx.Encrypt(emptyMailboxes, stream), "Encrypt"); Assert.Throws <ArgumentException> (() => ctx.Encrypt(emptyPubkeys, stream), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, mailboxes, null), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, pubkeys, null), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(mailboxes, null), "Encrypt"); Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(pubkeys, null), "Encrypt"); // Export Assert.Throws <ArgumentNullException> (() => ctx.Export((PgpPublicKeyRingBundle)null), "Export"); Assert.Throws <ArgumentNullException> (() => ctx.Export((MailboxAddress[])null), "Export"); Assert.Throws <ArgumentNullException> (() => ctx.Export((PgpPublicKey[])null), "Export"); // GetDecryptedStream Assert.Throws <ArgumentNullException> (() => ctx.GetDecryptedStream(null), "GetDecryptedStream"); // GetDigestAlgorithmName Assert.Throws <ArgumentOutOfRangeException> (() => ctx.GetDigestAlgorithmName(DigestAlgorithm.None), "GetDigestAlgorithmName"); // Import Assert.Throws <ArgumentNullException> (() => ctx.Import((Stream)null), "Import"); Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpPublicKeyRing)null), "Import"); Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpPublicKeyRingBundle)null), "Import"); Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpSecretKeyRing)null), "Import"); Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpSecretKeyRingBundle)null), "Import"); // ImportSecretKeys Assert.Throws <ArgumentNullException> (() => ctx.ImportSecretKeys(null), "ImportSecretKeys"); // Sign Assert.Throws <ArgumentNullException> (() => ctx.Sign((MailboxAddress)null, DigestAlgorithm.Sha1, stream), "Sign"); Assert.Throws <ArgumentNullException> (() => ctx.Sign((PgpSecretKey)null, DigestAlgorithm.Sha1, stream), "Sign"); Assert.Throws <ArgumentNullException> (() => ctx.Sign(mailboxes[0], DigestAlgorithm.Sha1, null), "Sign"); Assert.Throws <ArgumentNullException> (() => ctx.Sign(key, DigestAlgorithm.Sha1, null), "Sign"); // SignAndEncrypt Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (MailboxAddress[])null, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, stream), "SignAndEncrypt"); Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "SignAndEncrypt"); Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, null), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, null), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, mailboxes, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, pubkeys, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, (MailboxAddress[])null, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, (PgpPublicKey[])null, stream), "SignAndEncrypt"); Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, emptyMailboxes, stream), "SignAndEncrypt"); Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, emptyPubkeys, stream), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, mailboxes, null), "SignAndEncrypt"); Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, pubkeys, null), "SignAndEncrypt"); // Supports Assert.Throws <ArgumentNullException> (() => ctx.Supports(null), "Supports"); // Verify Assert.Throws <ArgumentNullException> (() => ctx.Verify(null, stream), "Verify"); Assert.Throws <ArgumentNullException> (() => ctx.Verify(stream, null), "Verify"); // MultipartEncrypted // Encrypt Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt((MailboxAddress[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt((PgpPublicKey[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(pubkeys, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(null, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, (MailboxAddress[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(ctx, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(null, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, (PgpPublicKey[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(ctx, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, pubkeys, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(EncryptionAlgorithm.Cast5, (MailboxAddress[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(EncryptionAlgorithm.Cast5, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(EncryptionAlgorithm.Cast5, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(EncryptionAlgorithm.Cast5, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(EncryptionAlgorithm.Cast5, pubkeys, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(null, EncryptionAlgorithm.Cast5, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, EncryptionAlgorithm.Cast5, (MailboxAddress[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(ctx, EncryptionAlgorithm.Cast5, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, EncryptionAlgorithm.Cast5, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(null, EncryptionAlgorithm.Cast5, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.Encrypt(ctx, EncryptionAlgorithm.Cast5, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.Encrypt(ctx, EncryptionAlgorithm.Cast5, pubkeys, null)); // SignAndEncrypt Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(key, DigestAlgorithm.Sha1, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(key, DigestAlgorithm.Sha1, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(key, DigestAlgorithm.Sha1, pubkeys, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(null, mailboxes[0], DigestAlgorithm.Sha1, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, (MailboxAddress)null, DigestAlgorithm.Sha1, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, mailboxes[0], DigestAlgorithm.Sha1, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(ctx, mailboxes[0], DigestAlgorithm.Sha1, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, mailboxes[0], DigestAlgorithm.Sha1, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(null, key, DigestAlgorithm.Sha1, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, (PgpSecretKey)null, DigestAlgorithm.Sha1, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, key, DigestAlgorithm.Sha1, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(ctx, key, DigestAlgorithm.Sha1, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, key, DigestAlgorithm.Sha1, pubkeys, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(null, mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, (MailboxAddress)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(ctx, mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyMailboxes, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, null)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(null, key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, (PgpSecretKey)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, null, entity)); Assert.Throws <ArgumentException> (() => MultipartEncrypted.SignAndEncrypt(ctx, key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyPubkeys, entity)); Assert.Throws <ArgumentNullException> (() => MultipartEncrypted.SignAndEncrypt(ctx, key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, null)); var encrypted = new MultipartEncrypted(); Assert.Throws <ArgumentNullException> (() => encrypted.Accept(null)); Assert.Throws <ArgumentNullException> (() => encrypted.Decrypt(null)); Assert.Throws <ArgumentNullException> (() => encrypted.Decrypt(null, out signatures)); } }
/// <summary> /// Visit the multipart/encrypted MIME entity. /// </summary> /// <remarks> /// Visits the multipart/encrypted MIME entity. /// </remarks> /// <param name="encrypted">The multipart/encrypted MIME entity.</param> protected internal virtual void VisitMultipartEncrypted(MultipartEncrypted encrypted) { VisitMultipart(encrypted); }
/* * Encrypts an entity. */ static MultipartEncrypted Encrypt(MimeEntity entity, Node encryptionNode) { return(MultipartEncrypted.Encrypt(GetEncryptionKeys(encryptionNode), entity)); }