-
Notifications
You must be signed in to change notification settings - Fork 1
/
fencrypt
executable file
·75 lines (56 loc) · 1.67 KB
/
fencrypt
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
#!/bin/bash
#Title: fencrypt
#Author: Nathan Thompson
#Date: Jan 17/17
if [[ $1 = "-e" ]]; then
#first uses tar to archive and zip the folder
tar -czf "$2.tar.gz" "$2"
#gpg is used to encrypt the archive
gpg -o "encrypted.$2" --symmetric --cipher-algo AES256 "$2.tar.gz"
#the temporary compressed folder is then removed
rm "$2.tar.gz"
echo -n "Delete original unencrypted file of $2?(y/N) > "
read answer
if [ "$answer" == "y" ]; then
rm -r $2
echo "Unencrypted original of $2 removed."
fi
if [ $? -eq 0 ]; then
echo "Successfully encrypted $2 as encrypted.$2!"
else
echo "Failed to encrypt $2"
fi
elif [[ $1 = "-d" ]]; then
#gpg first decrypts the file
gpg -o "decrypted$2" -d "$2"
#next tar decompresses the folder
tar -xzf "decrypted$2"
#next the temporary compressed tar file is removed
rm "decrypted$2"
if [ $? -eq 0 ]; then
echo "Successfully decrypted $2"
echo -n "Remove encrypted original of $2?(y/N) > "
read answer
if [ "$answer" == "y" ]; then
rm $2
echo "Encrypted original of $2 removed."
fi
else
echo "Failed to decrypt $2"
fi
elif [[ $1 = "-h" ]]; then
echo "This shell script encrypts or decrypts a specified directory/folder using AES256"
echo "-------------------------------------"
echo "Options:"
echo " -e: Encrypts specified file"
echo " -d: Decrypts specified file"
echo "-------------------------------------"
echo "Example of encryption:"
echo " bash fencrypt -e mydirectory"
echo "Example of decryption:"
echo " bash fencrypt -d myencrypteddirectory"
echo "-------------------------------------"
echo "Author: Nathan Thompson"
else
echo "Error: invalid option. Try -h for instructions."
fi