-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_encryption_decryption.sh
More file actions
88 lines (62 loc) · 1.88 KB
/
file_encryption_decryption.sh
File metadata and controls
88 lines (62 loc) · 1.88 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
80
81
82
83
84
85
86
87
88
#!/bin/bash
encrypt_file(){
FILE=$(zenity --file-selection --title="Select the file to encrypt")
if [ -z "$FILE" ]; then
zenity --error --text="No file selected"
exit 1
fi
Op_file=$(zenity --file-selection --save --confirm-overwrite --title="Save Encrypted as:")
if [ -z "$Op_file" ]; then
zenity --error --text="File Not Selected"
exit 1
fi
passwd=$(zenity --password --title="Enter Encryption Password")
if [ -z "$passwd" ]; then
zenity --error --text="No password entered"
exit 1
fi
openssl enc -des-ede3-cbc -salt -in "$FILE" -out "$Op_file" -pass pass:"$passwd"
if [ $? -eq 0 ]; then
zenity --info --text="File Encryption Successful"
else
zenity --error --text="Encryption Failed"
fi
}
decrypt_file(){
FILE=$(zenity --file-selection --title="Select a file to decrypt")
if [ -z "$FILE" ]; then
zenity --error --text="No file selected"
exit 1
fi
Op_file=$(zenity --file-selection --save --confirm-overwrite --title="Save decrypted as:")
if [ -z "$Op_file" ]; then
zenity --error --text="File Not Selected"
exit 1
fi
passwd=$(zenity --password --title="Enter Password to Decrypt")
if [ -z "$passwd" ]; then
zenity --error --text="No password entered"
exit 1
fi
echo "$passwd" > password.txt
openssl enc -d -des-ede3-cbc -salt -in "$FILE" -out "$Op_file" -pass file: password.txt
rm password.txt
if [ $? -eq 0 ]; then
zenity --info --text="File Decrypted Successful"
else
zenity --error --text="Decryption Failed"
fi
}
ACTION=$(zenity --list --radiolist --column "Select" --column "Action" TRUE "Encrypt" FALSE "Decrypt" --title="Choose Action")
case $ACTION in
Encrypt)
encrypt_file
;;
Decrypt)
decrypt_file
;;
*)
zenity --error --text="No valid operation chosen"
exit 1
;;
esac