Open Pgp ContextEncrypt Async(Encryption Algorithm, IEnumerablePgpPublicKey, Stream, Cancellation Token) Method
Asynchronously encrypt the specified content for the specified recipients.
Definition
Namespace: MimeKit.Cryptography
Assembly: MimeKit.Cryptography (in MimeKit.Cryptography.dll) Version: 5.0.0
A new MimePart instance containing the encrypted data.
Assembly: MimeKit.Cryptography (in MimeKit.Cryptography.dll) Version: 5.0.0
C#
public Task<MimePart> EncryptAsync(
EncryptionAlgorithm algorithm,
IEnumerable<PgpPublicKey> recipients,
Stream content,
CancellationToken cancellationToken = default
)Parameters
- algorithm EncryptionAlgorithm
- The encryption algorithm.
- recipients IEnumerablePgpPublicKey
- The recipients.
- content Stream
- The content.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
TaskMimePartA new MimePart instance containing the encrypted data.
Remarks
Asynchronously encrypts the specified content for the specified recipients.
Exceptions
| ArgumentNullException |
recipients is . -or- content is . |
| ArgumentException |
One or more of the recipient keys cannot be used for encrypting. -or- No recipients were specified. |
| NotSupportedException | The specified encryption algorithm is not supported. |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| IOException | An error occurred while reading the content stream. |
| PgpException | An OpenPGP error occurred while encrypting the content, such as failing to encrypt the session key for one of the recipients. |