Mime Message ExtensionsSign And Encrypt Async(Mime Message, Cryptography Context, Digest Algorithm, Cancellation Token) Method
Definition
Assembly: MimeKit.Cryptography (in MimeKit.Cryptography.dll) Version: 5.0.0
public static Task SignAndEncryptAsync(
this MimeMessage message,
CryptographyContext ctx,
DigestAlgorithm digestAlgo,
CancellationToken cancellationToken = default
)Parameters
- message MimeMessage
- The message to sign and encrypt.
- ctx CryptographyContext
- The cryptography context.
- digestAlgo DigestAlgorithm
- The digest algorithm.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
TaskAn asynchronous task context.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type MimeMessage. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).Remarks
If either of the Resent-Sender or Resent-From headers are set, then the message will be signed using the Resent-Sender (or first mailbox in the Resent-From) address as the signer address, otherwise the Sender or From address will be used instead.
Likewise, if either of the Resent-Sender or Resent-From headers are set, then the message will be encrypted to all of the addresses specified in the Resent headers (Resent-Sender, Resent-From, Resent-To, Resent-Cc, and Resent-Bcc), otherwise the message will be encrypted to all of the addresses specified in the standard address headers (Sender, From, To, Cc, and Bcc).
Exceptions
| ArgumentNullException | ctx is . |
| ArgumentException | An unknown type of cryptography context was used. |
| ArgumentOutOfRangeException | The digestAlgo was out of range. |
| InvalidOperationException |
The message Body has not been set. -or- No sender has been specified. -or- No recipients have been specified. |
| NotSupportedException | The digestAlgo is not supported. |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| CertificateNotFoundException | A certificate could not be found for the signer or one or more of the recipients. |
| PrivateKeyNotFoundException | The private key could not be found for the sender. |
| PublicKeyNotFoundException | The public key could not be found for one or more of the recipients. |