-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcrypt.sh
More file actions
executable file
·81 lines (61 loc) · 1.14 KB
/
crypt.sh
File metadata and controls
executable file
·81 lines (61 loc) · 1.14 KB
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
#!/bin/bash
#this is a script to encrypt all files in a user given directory
#handle commandline arguments
if [ $# -eq 0 ]
then
echo "\e[31mUsage \e[39m: crypt -[E/D]"
echo "D- Decrypt files"
echo "E- Encrypt files"
exit 1
fi
if [ $1 != '-E' ] && [ $1 != '-D' ]
then
echo "Invalid argument $1"
exit 1
fi
#read path of the directory from user
echo -n "Directory path : "
read path
#read password from user
echo -n "Password : "
stty -echo
read pass
echo
stty echo
if [ $1 != '-D' ]
then
echo -n "Confirm Password : "
stty -echo
read pass2
stty echo
echo
if [ $pass != $pass2 ]
then
echo "\e[91mPassword mismatch !"
exit 1
fi
else
echo ""
fi
files="$path/*"
#loop through files in the given directory
for f in $files
do
if [ $1 != '-D' ]
then
openssl enc -aes-256-cbc -salt -in "$f" -out "$f.en" -k $pass
echo "\e[92m$f encypted"
rm -r "$f"
else
openssl enc -aes-256-cbc -d -in "$f" -out "$f.d" -k $pass 2> /dev/null
if [ $? -ne 1 ]
then
rm -r "$f"
rename 's/\.en\.d//' "$f.d"
echo "\e[92m$f Decrypted !"
else
rm "$f.d"
echo "\e[91mDecryption Failed !"
fi
fi
done