Encrypt#

Description#

Encrypts data with a KMS key. You can use this method to encrypt a small amount of data.

Request Parameters#

Required parameters#

  • KeyId — The ID of the KMS key. You can specify an alias name with the alias/ prefix as the identifier.

    • Type: String

    • Required: Yes

  • Plaintext — The original data.

    • Type: Base64-encoded binary data

    • Required: Yes

    • Length constraints: From 1 to 4096 bytes

Optional parameters#

  • EncryptionContext — The encryption context used as additional authenticated data (AAD).

    • Type: Map of strings

    • Required: No

    • Constraints: The total length of all strings in UTF-8 encoding must not exceed 6144 bytes

Response Elements#

  • CiphertextBlob — The encrypted data.

    • Type: Base64-encoded binary data

    • Length constraints: From 1 to 6144 bytes

Examples#

Sample Request#

POST / HTTP/1.1
Host: kms.<region>.<domain>
Content-Length: <PayloadSizeBytes>
Content-Type: application/x-amz-json-1.1
Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=<Headers>, Signature=<Signature>
X-Amz-Date: <Date>
X-Amz-Target: TrentService.Encrypt

{
    "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab",
    "Plaintext": "SGVsbG8sIHdvcmxkIQ=="
}

Sample Response#

HTTP/1.1 200 OK
Content-Type: application/x-amz-json-1.1

{
    "CiphertextBlob": "AAAAAM4+iMkZakUYoOjQVwv/+Rble77a9sKsVR2b6Ip5dCTccveHBXG2NShREn9ez3WXAEJYOHwKspxa0GfmLieIiz9sUXPXnfUMTUrLWKtrft+x0dZvcvWU0YY8"
}