Created
September 10, 2022 15:19
-
-
Save ardeshir/1404a24e8123e0952fbd24a47f63832e to your computer and use it in GitHub Desktop.
encrypt your files
This file contains 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
#!/bin/bash | |
set -e | |
if [[ "$#" -ne 4 ]]; then | |
echo "Usage: encrypt.sh <CMK_ID> <AWS_REGION> <INPUT_FILE> <OUTPUT_FILE>" | |
exit | |
fi | |
CMK_ID="$1" | |
AWS_REGION="$2" | |
INPUT_FILE="$3" | |
OUTPUT_FILE="$4" | |
echo "Encrypting contents of $INPUT_FILE using CMK $CMK_ID..." | |
ciphertext=$(aws kms encrypt \ | |
--key-id "$CMK_ID" \ | |
--region "$AWS_REGION" \ | |
--plaintext "fileb://$INPUT_FILE" \ | |
--output text \ | |
--query CiphertextBlob) | |
echo "Writing result to $OUTPUT_FILE..." | |
echo "$ciphertext" > "$OUTPUT_FILE" | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment