MimeKit.Cryptography.MultipartEncrypted.Decrypt C# (CSharp) Method

Decrypt() public method

Decrypts the MultipartEncrypted part.
Decrypts the MultipartEncrypted and extracts any digital signatures in cases where the content was also signed.
/// is null. /// /// The protocol parameter was not specified. /// -or- /// The multipart is malformed in some way. /// /// The provided does not support the protocol parameter. /// /// The private key could not be found to decrypt the encrypted data. /// /// The user chose to cancel the password prompt. /// /// 3 bad attempts were made to unlock the secret key. ///
public Decrypt ( MimeKit.Cryptography.OpenPgpContext ctx, DigitalSignatureCollection &signatures ) : MimeEntity
ctx MimeKit.Cryptography.OpenPgpContext The OpenPGP cryptography context to use for decrypting.
signatures DigitalSignatureCollection A list of digital signatures if the data was both signed and encrypted.
return MimeEntity
		public MimeEntity Decrypt (OpenPgpContext ctx, out DigitalSignatureCollection signatures)
		{
			if (ctx == null)
				throw new ArgumentNullException ("ctx");

			var protocol = ContentType.Parameters["protocol"];
			if (string.IsNullOrEmpty (protocol))
				throw new FormatException ();

			protocol = protocol.Trim ().ToLowerInvariant ();
			if (!ctx.Supports (protocol))
				throw new NotSupportedException ();

			if (Count < 2)
				throw new FormatException ();

			var version = this[0] as MimePart;
			if (version == null)
				throw new FormatException ();

			var ctype = version.ContentType;
			var value = string.Format ("{0}/{1}", ctype.MediaType, ctype.MediaSubtype);
			if (value.ToLowerInvariant () != protocol)
				throw new FormatException ();

			var encrypted = this[1] as MimePart;
			if (encrypted == null || encrypted.ContentObject == null)
				throw new FormatException ();

			if (!encrypted.ContentType.IsMimeType ("application", "octet-stream"))
				throw new FormatException ();

			using (var memory = new MemoryBlockStream ()) {
				encrypted.ContentObject.DecodeTo (memory);
				memory.Position = 0;

				return ctx.Decrypt (memory, out signatures);
			}
		}

Same methods

MultipartEncrypted::Decrypt ( ) : MimeEntity
MultipartEncrypted::Decrypt ( DigitalSignatureCollection &signatures ) : MimeEntity
MultipartEncrypted::Decrypt ( MimeKit.Cryptography.OpenPgpContext ctx ) : MimeEntity