Skip to main content

Encrypt

Encrypts plaintext into ciphertext using a KMS key.

Description

The `Encrypt` operation uses a KMS key to encrypt data. This operation is the basic encryption operation provided by QKMS. You can use it to encrypt small amounts of arbitrary data, such as a personal identifier or database password.

note
  • The KMS key that you use for this operation must be in a compatible key state.
  • If you use a symmetric encryption KMS key, you can use the ciphertext in another cryptographic operation, such as `Decrypt`.
  • For asymmetric KMS keys, you can encrypt data only with RSA public keys.
  • The maximum size of the data you can encrypt varies with the type of KMS key and encryption algorithm that you are using.

Request Syntax

Headers

NameDescriptionRequiredType
Content-TypeMust be "application/x-amz-json-1.1"Yesstring
X-Amz-TargetMust be "TrentService.Encrypt"Yesstring

Request Body

NameDescriptionRequiredType
KeyIdThe identifier of the KMS key to use for encryption. This can be the key ID or key ARN of the KMS key.Yesstring
PlaintextThe data to encrypt.Yesblob
EncryptionContextA set of key-value pairs that you can attach to an encryption operation.Noobject
GrantTokensA list of grant tokens that represent grants that can be used to encrypt with the KMS key.Noarray[string]
EncryptionAlgorithmThe encryption algorithm that will be used to encrypt the plaintext.

Valid Values: SYMMETRIC_DEFAULT, RSAES_OAEP_SHA_1, RSAES_OAEP_SHA_256.
Nostring
POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.Encrypt
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Plaintext": "SGVsbG8gV29ybGQ=", "EncryptionContext": { "Department": "Finance" }, "GrantTokens": [ "AQpAM2RhZTk1MGMyNTk2ZmZmMzEyYWVhOWViN2I1MWM4Mzc0MWFiYjc0ZDE1ODkyNGFlNTIzODZhMzgyZjBlNDkxOAF4" ], "EncryptionAlgorithm": "SYMMETRIC_DEFAULT" }
Values in italics indicate user input and should be replaced with actual values.

Examples

Example 1: Encrypt data using a symmetric encryption KMS key

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.Encrypt
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Plaintext": "SGVsbG8gV29ybGQ=", "EncryptionContext": { "Department": "Finance" } }
Values in italics indicate user input and should be replaced with actual values.
HTTP/1.1 200 OK
Content-Type: application/x-amz-json-1.1
{ "CiphertextBlob": "AQICAHiWj6qDgGqSQXkNHcsbq8Q3+q6lThTZqXXRRXYtGhEQXwEH5qV5eN9LQI6CtDwBUvNVAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMeq6+5Ey7LGAKorXtAgEQgDsgli8KqqW4qp0g9ZWnHdRGYc3ZJzpV3xH9qVGFRwzVVKJNK/Ey/fGS2tl4TOQXLcTYJMEOxR8gPjA=", "KeyId": "arn:verenc:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "EncryptionAlgorithm": "SYMMETRIC_DEFAULT" }
Values in italics indicate variable response values.

Response Elements

NameDescriptionRequiredType
CiphertextBlobThe encrypted data (ciphertext).NoString
KeyIdThe Amazon Resource Name (ARN) of the KMS key that was used to encrypt the data.NoString
EncryptionAlgorithmThe encryption algorithm that was used to encrypt the data.NoString

Special Errors

Error CodeDescription
DependencyTimeoutExceptionThe system timed out while trying to fulfill the request.
DisabledExceptionThe request was rejected because the specified KMS key is disabled.
InvalidGrantTokenExceptionThe request was rejected because the specified grant token is not valid.
InvalidKeyUsageExceptionThe request was rejected because the specified KeyId value cannot be used for this operation.
KeyUnavailableExceptionThe request was rejected because the specified KMS key was not available.
KMSInternalExceptionAn internal error occurred.
KMSInvalidStateExceptionThe request was rejected because the key state is not valid for this operation.
NotFoundExceptionThe request was rejected because the specified key was not found.

Permissions

To use the `Encrypt` operation, you must have the following permissions:

  • `kms:Encrypt` on the KMS key (specified in the policy)

Try It Out

Test Encrypt

Encrypt data using a KMS key.

Coming Soon

This feature is currently under development and will be available soon.