encrypt - encrypt

Encrypts an arbitrary sequence of bytes using an encryption key that is stored in a key vault.
The ENCRYPT operation encrypts an arbitrary sequence of bytes using an encryption key that is stored in Azure Key Vault. Note that the ENCRYPT operation only supports a single block of data, the size of which is dependent on the target key and the encryption algorithm to be used. The ENCRYPT operation is only strictly necessary for symmetric keys stored in Azure Key Vault since protection with an asymmetric key can be performed using public portion of the key. This operation is supported for asymmetric keys as a convenience for callers that have a key-reference but do not have access to the public key material. This operation requires the keys/encrypt permission.

POST {vaultBaseUrl}/keys/{key-name}/{key-version}/encrypt?api-version=2025-07-01

URI Parameters

Name In Required Type Description
key-name
path True

string

The name of the key.

key-version
path True

string

The version of the key.

vaultBaseUrl
path True

string (uri)

api-version
query True

string

minLength: 1

The API version to use for this operation.

Request Body

Name Required Type Description
alg True

JsonWebKeyEncryptionAlgorithm

algorithm identifier

value True

string (base64url)

The value to operate on.

aad

string (base64url)

Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms.

iv

string (base64url)

Cryptographically random, non-repeating initialization vector for symmetric algorithms.

tag

string (base64url)

The tag to authenticate when performing decryption with an authenticated algorithm.

Responses

Name Type Description
200 OK

KeyOperationResult

The request has succeeded.

Other Status Codes

KeyVaultError

An unexpected error response.

Security

OAuth2Auth

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
https://vault.azure.net/.default

Examples

Encrypt example

Sample request

POST https://myvault.vault.azure.net//keys/sdktestkey/f6bc1f3d37c14b2bb1a2ebb4b24e9535/encrypt?api-version=2025-07-01

{
  "alg": "RSA1_5",
  "value": "5ka5IVsnGrzufA"
}

Sample response

{
  "kid": "https://myvault.vault.azure.net/keys/sdktestkey/f6bc1f3d37c14b2bb1a2ebb4b24e9535",
  "value": "CR0Hk0z72oOit5TxObqRpo-WFGZkb5BeN1C0xJFKHxzdDCESYPCNB-OkiWVAnMcSyu6g2aC8riVRRxY5MC2CWKj-CJ_SMke5X2kTi5yi4hJ5vuOLzmg_M6Bmqib7LsI-TeJHr9rs3-tZaSCdZ2zICeFWYduWV5rPjTnAD98epTorT8AA1zMaYHMIhKpmttcj18-dHr0E0T55dgRtsjK04uC3FlRd3odl4RhO1UHAmYpDd5FUqN-20R0dK0Zk8F8sOtThLhEmuLvqPHOCUBiGUhHA4nRDq1La4SUbThu2KMQJL6BbxxEymuliaYcNNtW7MxgVOf6V3mFxVNRY622i9g"
}

Definitions

Name Description
Error
JsonWebKeyEncryptionAlgorithm

An algorithm used for encryption and decryption.

KeyOperationResult

The key operation result.

KeyOperationsParameters

The key operations parameters.

KeyVaultError

The key vault error exception.

Error

Name Type Description
code

string

The error code.

innererror

Error

The key vault server error.

message

string

The error message.

JsonWebKeyEncryptionAlgorithm

An algorithm used for encryption and decryption.

Value Description
RSA-OAEP

[Not recommended] RSAES using Optimal Asymmetric Encryption Padding (OAEP), as described in https://tools.ietf.org/html/rfc3447, with the default parameters specified by RFC 3447 in Section A.2.1. Those default parameters are using a hash function of SHA-1 and a mask generation function of MGF1 with SHA-1. Microsoft recommends using RSA_OAEP_256 or stronger algorithms for enhanced security. Microsoft does not recommend RSA_OAEP, which is included solely for backwards compatibility. RSA_OAEP utilizes SHA1, which has known collision problems.

RSA-OAEP-256

RSAES using Optimal Asymmetric Encryption Padding with a hash function of SHA-256 and a mask generation function of MGF1 with SHA-256.

RSA1_5

[Not recommended] RSAES-PKCS1-V1_5 key encryption, as described in https://tools.ietf.org/html/rfc3447. Microsoft recommends using RSA_OAEP_256 or stronger algorithms for enhanced security. Microsoft does not recommend RSA_1_5, which is included solely for backwards compatibility. Cryptographic standards no longer consider RSA with the PKCS#1 v1.5 padding scheme secure for encryption.

A128GCM

128-bit AES-GCM.

A192GCM

192-bit AES-GCM.

A256GCM

256-bit AES-GCM.

A128KW

128-bit AES key wrap.

A192KW

192-bit AES key wrap.

A256KW

256-bit AES key wrap.

A128CBC

128-bit AES-CBC.

A192CBC

192-bit AES-CBC.

A256CBC

256-bit AES-CBC.

A128CBCPAD

128-bit AES-CBC with PKCS padding.

A192CBCPAD

192-bit AES-CBC with PKCS padding.

A256CBCPAD

256-bit AES-CBC with PKCS padding.

CKM_AES_KEY_WRAP

CKM AES key wrap.

CKM_AES_KEY_WRAP_PAD

CKM AES key wrap with padding.

KeyOperationResult

The key operation result.

Name Type Description
aad

string (base64url)

Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms.

iv

string (base64url)

Cryptographically random, non-repeating initialization vector for symmetric algorithms.

kid

string

Key identifier

tag

string (base64url)

The tag to authenticate when performing decryption with an authenticated algorithm.

value

string (base64url)

The result of the operation.

KeyOperationsParameters

The key operations parameters.

Name Type Description
aad

string (base64url)

Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms.

alg

JsonWebKeyEncryptionAlgorithm

algorithm identifier

iv

string (base64url)

Cryptographically random, non-repeating initialization vector for symmetric algorithms.

tag

string (base64url)

The tag to authenticate when performing decryption with an authenticated algorithm.

value

string (base64url)

The value to operate on.

KeyVaultError

The key vault error exception.

Name Type Description
error

Error

The key vault server error.