Compartilhar via


CryptographyClient.EncryptAsync Method

Definition

Overloads

EncryptAsync(EncryptionAlgorithm, Byte[], CancellationToken)

Encrypts the specified plaintext.

EncryptAsync(EncryptParameters, CancellationToken)

Encrypts plaintext.

EncryptAsync(EncryptionAlgorithm, Byte[], CancellationToken)

Source:
CryptographyClient.cs
Source:
CryptographyClient.cs

Encrypts the specified plaintext.

public virtual System.Threading.Tasks.Task<Azure.Security.KeyVault.Keys.Cryptography.EncryptResult> EncryptAsync (Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, System.Threading.CancellationToken cancellationToken = default);
abstract member EncryptAsync : Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm * byte[] * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Security.KeyVault.Keys.Cryptography.EncryptResult>
override this.EncryptAsync : Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm * byte[] * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Security.KeyVault.Keys.Cryptography.EncryptResult>
Public Overridable Function EncryptAsync (algorithm As EncryptionAlgorithm, plaintext As Byte(), Optional cancellationToken As CancellationToken = Nothing) As Task(Of EncryptResult)

Parameters

plaintext
Byte[]

The data to encrypt.

cancellationToken
CancellationToken

A CancellationToken to cancel the operation.

Returns

An EncryptResult containing the encrypted data along with all other information needed to decrypt it. This information should be stored with the encrypted data.

Exceptions

The specified algorithm does not match the key corresponding to the key identifier.

The local cryptographic provider threw an exception.

The key is invalid for the current operation.

The operation is not supported with the specified key.

The server returned an error. See Message for details returned from the server.

Remarks

Microsoft recommends you not use CBC without first ensuring the integrity of the ciphertext using an HMAC, for example. See https://docs.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode for more information.

Applies to

EncryptAsync(EncryptParameters, CancellationToken)

Source:
CryptographyClient.cs
Source:
CryptographyClient.cs

Encrypts plaintext.

public virtual System.Threading.Tasks.Task<Azure.Security.KeyVault.Keys.Cryptography.EncryptResult> EncryptAsync (Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters encryptParameters, System.Threading.CancellationToken cancellationToken = default);
abstract member EncryptAsync : Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Security.KeyVault.Keys.Cryptography.EncryptResult>
override this.EncryptAsync : Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Security.KeyVault.Keys.Cryptography.EncryptResult>
Public Overridable Function EncryptAsync (encryptParameters As EncryptParameters, Optional cancellationToken As CancellationToken = Nothing) As Task(Of EncryptResult)

Parameters

encryptParameters
EncryptParameters

An EncryptParameters containing the data to encrypt and other parameters for algorithm-dependent encryption.

cancellationToken
CancellationToken

A CancellationToken to cancel the operation.

Returns

An EncryptResult containing the encrypted data along with all other information needed to decrypt it. This information should be stored with the encrypted data.

Exceptions

The specified algorithm does not match the key corresponding to the key identifier.

encryptParameters is null.

The local cryptographic provider threw an exception.

The key is invalid for the current operation.

The operation is not supported with the specified key.

The server returned an error. See Message for details returned from the server.

Remarks

Microsoft recommends you not use CBC without first ensuring the integrity of the ciphertext using an HMAC, for example. See https://docs.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode for more information.

Applies to