-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypt-decrypt
39 lines (32 loc) · 937 Bytes
/
crypt-decrypt
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
#!/bin/bash
PROPERTIES_FILE='default.properties'
HASH_PROPERTY='download.password'
exists_property() {
local __property="$1"
grep -Eqs "^$__property" "$PROPERTIES_FILE"
}
get_password() {
if exists_property "$HASH_PROPERTY"; then
password=$(grep "$HASH_PROPERTY" "$PROPERTIES_FILE" | cut -f2 -d=)
sed -i "/$HASH_PROPERTY/d" "$PROPERTIES_FILE"
else
echo "Type your Liferay password:"
read -s password
fi
}
encrypt() {
get_password
local __hash=$(printf "$password" | openssl enc -aes-256-ctr | xxd -p)
echo $HASH_PROPERTY=$__hash >> "$PROPERTIES_FILE"
}
decrypt() {
if exists_property "$HASH_PROPERTY"; then
local __hash=$(grep "$HASH_PROPERTY" "$PROPERTIES_FILE" | cut -f2 -d=)
echo $(printf "$__hash" | xxd -p -r | openssl aes-256-ctr -d)
fi
}
case "$1" in
enc) encrypt ;;
dec) decrypt ;;
*) echo "Usage $0: [enc|dec]" ;;
esac