AWS KMS decrypt for base64 encoded input

With AWS CLI version 2:

1
2
𝜆 aws --version
aws-cli/2.1.17 Python/3.7.4 Darwin/20.3.0 exe/x86_64 prompt/off

Encrypt with AWS KMS key:

1
2
3
4
5
6
7
𝜆 aws kms encrypt --profile personal \
--key-id e2695b79-cbe0-4c16-aa5e-b7dbf52df1f9 \
--plaintext "string-to-encrypt" \
--output text \
--query CiphertextBlob \
--cli-binary-format raw-in-base64-out
AQICAHjbJrIPgME ... lILuBSUdA==

Decrypt with AWS KMS key:

1
2
3
4
5
𝜆 echo "AQICAHjbJrIPgME ... lILuBSUdA==" | base64 -D | \
aws kms decrypt --profile personal \
--ciphertext-blob fileb:///dev/stdin \
--output text \
--query Plaintext | base64 -D

Reference

Contents