Created
September 2, 2018 06:52
-
-
Save ytensor42/14437ebe738ebee1b580750ce7fadeb5 to your computer and use it in GitHub Desktop.
Encrypt / Decrypt using aws kms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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