Skip to content

Instantly share code, notes, and snippets.

@ardeshir
Created September 10, 2022 15:19
Show Gist options
  • Save ardeshir/1404a24e8123e0952fbd24a47f63832e to your computer and use it in GitHub Desktop.
Save ardeshir/1404a24e8123e0952fbd24a47f63832e to your computer and use it in GitHub Desktop.
encrypt your files
#!/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