-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.sh
executable file
·60 lines (55 loc) · 978 Bytes
/
decrypt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
if [ "$(uname)" = "Darwin" ]; then
decode_opt="-D"
else
decode_opt="-d"
fi
decode() {
base64 "$decode_opt"
}
usage() {
echo "Usage $0 " \
"[--profile <aws-profile>] " \
"[--output <output-file>] " \
"[<input-file>] " \
>&2
}
aws_opts=()
input_file=
output_file=
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--help|help|-h)
usage
exit 3
;;
--profile|-p)
aws_opts+=(--profile "$2")
shift
;;
--output|-o)
output_file="$2"
shift
;;
*)
if [ "$input_file" = "" ]; then
input_file="$1"
else
echo "Unrecognized option '${key}'" >&2
usage
exit 2
fi
;;
esac
shift
done
input_file="${input_file:-/dev/stdin}"
cat "$input_file" | \
decode | \
aws ${aws_opts[@]} kms decrypt \
--ciphertext-blob fileb:///dev/stdin\
--query Plaintext \
--output text | \
decode \
> "${output_file:-/dev/stdout}"