Exemplo n.º 1
0
        /// <summary>
        /// Decrypts the content.
        /// </summary>
        /// <remarks>
        /// Decrypts the content using the specified <see cref="SecureMimeContext"/>.
        /// </remarks>
        /// <returns>The decrypted <see cref="MimeKit.MimeEntity"/>.</returns>
        /// <param name="ctx">The S/MIME context to use for decrypting.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="ctx"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// The "smime-type" parameter on the Content-Type header is not "enveloped-data".
        /// </exception>
        /// <exception cref="Org.BouncyCastle.Cms.CmsException">
        /// An error occurred in the cryptographic message syntax subsystem.
        /// </exception>
        public MimeEntity Decrypt(SecureMimeContext ctx)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            if (SecureMimeType != SecureMimeType.EnvelopedData)
            {
                throw new InvalidOperationException();
            }

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

                return(ctx.Decrypt(memory));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decrypt the enveloped-data.
        /// </summary>
        /// <remarks>
        /// Decrypts the enveloped-data using the specified <see cref="SecureMimeContext"/>.
        /// </remarks>
        /// <returns>The decrypted <see cref="MimeKit.MimeEntity"/>.</returns>
        /// <param name="ctx">The S/MIME context to use for decrypting.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="ctx"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// The "smime-type" parameter on the Content-Type header is not "enveloped-data".
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        /// The operation was cancelled via the cancellation token.
        /// </exception>
        /// <exception cref="Org.BouncyCastle.Cms.CmsException">
        /// An error occurred in the cryptographic message syntax subsystem.
        /// </exception>
        public MimeEntity Decrypt(SecureMimeContext ctx, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (ctx == null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }

            if (SecureMimeType != SecureMimeType.EnvelopedData && SecureMimeType != SecureMimeType.Unknown)
            {
                throw new InvalidOperationException();
            }

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

                return(ctx.Decrypt(memory, cancellationToken));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decrypt using the specified <see cref="CryptographyContext"/>.
        /// </summary>
        /// <returns>The decrypted <see cref="MimeKit.MimeEntity"/>.</returns>
        /// <param name="ctx">The S/MIME context to use for decrypting.</param>
        /// <param name="signatures">The list of digital signatures for this application/pkcs7-mime part.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="ctx"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// The "smime-type" parameter on the Content-Type header does not support decryption.
        /// </exception>
        public MimeEntity Decrypt(SecureMimeContext ctx, out IList <IDigitalSignature> signatures)
        {
            // FIXME: find out what exceptions BouncyCastle can throw...
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            if (SecureMimeType != SecureMimeType.EnvelopedData)
            {
                throw new InvalidOperationException();
            }

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

                return(ctx.Decrypt(memory, out signatures));
            }
        }
Exemplo n.º 4
0
		/// <summary>
		/// Decrypts the content.
		/// </summary>
		/// <remarks>
		/// Decrypts the content using the specified <see cref="SecureMimeContext"/>.
		/// </remarks>
		/// <returns>The decrypted <see cref="MimeKit.MimeEntity"/>.</returns>
		/// <param name="ctx">The S/MIME context to use for decrypting.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="ctx"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The "smime-type" parameter on the Content-Type header is not "enveloped-data".
		/// </exception>
		/// <exception cref="Org.BouncyCastle.Cms.CmsException">
		/// An error occurred in the cryptographic message syntax subsystem.
		/// </exception>
		public MimeEntity Decrypt (SecureMimeContext ctx)
		{
			if (ctx == null)
				throw new ArgumentNullException ("ctx");

			if (SecureMimeType != SecureMimeType.EnvelopedData)
				throw new InvalidOperationException ();

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

				return ctx.Decrypt (memory);
			}
		}