Repository navigation
Expand file tree
/
Copy pathCryptUtil.sh
More file actions
97 lines (87 loc) · 2.66 KB
/
Copy pathCryptUtil.sh
File metadata and controls
97 lines (87 loc) · 2.66 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
89
90
91
92
93
94
95
96
97
#!/bin/sh
## Crypto tool for symetric file encryption/decryption, using zenity and gpg.
## Supported Ciphers: CAST5, TWOFISH, BLOWFISH, 3DES, AES, AES192, AES256.
title="CryptUtil"
err_pass="<b>You MUST provide a passphrase.</b>"
err_unexp="<b>An unexpected error occured.</b>"
enc_success="<b>Your file has been successfully encrypted.</b>"
dec_success="<b>Your file has been successfully decrypted.</b>"
check(){
if [ "$1" = "encrypt" ]
then
if [ -e "$selection.gpg" ]
then
zenity --info --title="$title" --text="$enc_success\n\nLocation of encrypted file:\n<i>$selection.gpg</i>"
exit 0
else
zenity --error --title="Error" --text="$err_unexp\nEncryption failed."
exit 0
fi
fi
if [ "$1" = "decrypt" ]
then
if [ -e "$outfile" ]
then
zenity --info --title="$title" --text="$dec_success\n\nLocation of decrypted file:\n<i>$outfile</i>"
exit 0
else
zenity --error --title="Error" --text="$err_unexp\nDecryption failed."
exit 0
fi
fi
}
encrypt(){
cipher=`zenity --list --radiolist --title="$title" --text="Choose the cipher:" --column="" --column="Type" --print-column="2" \
TRUE "AES256" \
FALSE "AES192" \
FALSE "AES" \
FALSE "3DES" \
FALSE "BLOWFISH" \
FALSE "TWOFISH" \
FALSE "CAST5"`
passphrase=`zenity --entry --hide-text --entry-text="$passphrase" --title="$title" --text="Passphrase for: ${selection##*/}" "" 2>&1`
if [ "$passphrase" = "" ]
then
zenity -error --title="Error" --text="$err_pass"
exit 0
else
echo "$passphrase" | gpg --batch --passphrase-fd 0 --cipher-algo "$cipher" -c "$selection"
fi
}
decrypt(){
passphrase=`zenity --entry --hide-text --entry-text="$passphrase" --title="$title" --text="Passphrase for: ${selection##*/}" "" 2>&1`
if [ "$passphrase" = "" ]
then
zenity --error --title="Error" --text="$err_pass"
exit 0
else
outfile=${selection%.*}
echo "$passphrase" | gpg -o "$outfile" --batch --passphrase-fd 0 -d "$selection"
fi
}
zenity --question --title="$title" --text="<i><b><tt><big>Symetric Crypting Utility</big></tt></b></i>\n\nSupported ciphers:\n- AES256\n- AES192\n- AES\n- 3DES\n- BLOWFISH\n- TWOFISH\n- CAST5 \n\n<i><small>--- Requires GPG ---</small></i>" && \
ok="True"
if [ "$ok" != "True" ]
then
exit 0
else
task=`zenity --list --radiolist --title="$title" --text="Choose a task to perform:" --column="" --column="Task" --column="" --print-column="3" --hide-column="3" \
FALSE "Encrypt a file" "encrypt" \
FALSE "Decrypt a file" "decrypt"`
if [ "$task" = "" ]
then
exit 0
else
selection=`zenity --file-selection --title="$title"`
if [ "$task" = "encrypt" ]
then
encrypt
check "encrypt"
fi
if [ "$task" = "decrypt" ]
then
decrypt
check "decrypt"
fi
fi
fi