Skip to content

Instantly share code, notes, and snippets.

@ytensor42
Created September 2, 2018 06:52
Show Gist options
  • Select an option

  • Save ytensor42/14437ebe738ebee1b580750ce7fadeb5 to your computer and use it in GitHub Desktop.

Select an option

Save ytensor42/14437ebe738ebee1b580750ce7fadeb5 to your computer and use it in GitHub Desktop.
Encrypt / Decrypt using aws kms
# Command line Encrypt & Decrypt
## Encrypt
TEXT_TO_ENCRYPT="secret text that I want to encrypt"
KMS_KEY_ID="kms key id, can get it by aws kms list-keys"
# stdout
$ aws kms encrypt --key-id $KMS_KEY_ID --plaintext $TEXT_TO_ENCRYPT --output text --query CiphertextBlob
AQICA....
.....dA==
# file
$ aws kms encrypt --key-id $KMS_KEY_ID --plaintext $TEXT_TO_ENCRYPT --output text --query CiphertextBlob | base64 --decode > filename
## Decrypt
ENCRYPTED_TEXT="AQICA....dA=="
$ aws kms decrypt --ciphertext-blob fileb://<(echo -n "$ENCRYPTED_TEXT" | base64 --decode) --output text --query Plaintext | base64 --decode
secret text that I want to encrypt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment