-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption_tool.sh
executable file
·125 lines (104 loc) · 3.1 KB
/
encryption_tool.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Author: Jiamao Zheng, jiamaoz@yahoo.com, 2017
#--------------------------Password file-----------------------------
# place password in the text file `pass'
# chmod 400 pass
# save it in a safe place (e.g. ~/.ssh/)
#--------------------------Encryption--------------------------------
day=$(date +%F)
LOG_FILE="$day.txt"
echo
echo >> $LOG_FILE
if [ $3 = "encrypt" ]; then
log_file="---------------------------------- start encrypting on $1 ----------------------------------"
echo $log_file
echo $log_file >> $LOG_FILE
echo
echo >> $LOG_FILE
counter=0
start=$SECONDS
find $1 -not -path '*/\.*' -type f \( ! -iname '.*' \) -print0 | while read -d $'\0' file; do
if [[ ${file: -4} != ".enc" ]] && [ -f $2 ]; then
log_file="encrypting $file ..."
echo $log_file
echo $log_file >> $LOG_FILE
if $( openssl aes-256-cbc -in "$file" -out "$file.enc" -pass file:$2 ); then
log_file="deleting $file ..."
echo $log_file
echo $log_file >> $LOG_FILE
rm "$file"
let counter++
end=$SECONDS
log_file="$counter files have been encrypted in $((end-start)) seconds"
echo $log_file
echo $log_file >> $LOG_FILE
echo
echo >> $LOG_FILE
else
log_file=$( openssl aes-256-cbc -in "$file" -out "$file.enc" -pass file:$2 2>&1)
rm "$file.enc"
echo
echo $log_file >> $LOG_FILE
break
fi
else
if [ ! -f $2 ]; then
log_file="password file doesn't exit!"
echo $log_file
echo $log_file >> $LOG_FILE
break
fi
fi
done
log_file="---------------------------------- finish encrypting on $1 ----------------------------------"
echo $log_file
echo $log_file >> $LOG_FILE
fi
#------------------------Decryption--------------------------------
if [ $3 = "decrypt" ]; then
log_file="---------------------------------- start decrypting on $1 ----------------------------------"
echo $log_file
echo $log_file >> $LOG_FILE
echo
echo >> $LOG_FILE
counter=0
start=$SECONDS
find $1 -not -path '*/\.*' -type f \( ! -iname '.*' \) -print0 | while read -d $'\0' file; do
if [ ${file: -4} = ".enc" ] && [ -f $2 ]; then
log_file="decrypting $file ..."
echo $log_file
echo $log_file >> $LOG_FILE
if $( openssl aes-256-cbc -d -in "$file" -out "${file/%????}" -pass file:$2); then
log_file="deleting $file ..."
echo $log_file
echo $log_file >> $LOG_FILE
rm "$file"
let counter++
end=$SECONDS
log_file="$counter files have been decrypted in $((end-start)) seconds"
echo $log_file
echo $log_file >> $LOG_FILE
echo
echo >> $LOG_FILE
else
log_file=$( openssl aes-256-cbc -d -in "$file" -out "${file/%????}" -pass file:$2 2>&1)
rm "${file/%????}"
echo
echo $log_file >> $LOG_FILE
break
fi
else
if [ ! -f $2 ]; then
log_file="password file doesn't exit!"
echo $log_file
echo $log_file >> $LOG_FILE
break
fi
fi
done
log_file="---------------------------------- finish decrypting on $1 ----------------------------------"
echo $log_file
echo $log_file >> $LOG_FILE
fi
echo
echo >> $LOG_FILE