-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpg_script.sh
More file actions
45 lines (39 loc) · 1.3 KB
/
Copy pathgpg_script.sh
File metadata and controls
45 lines (39 loc) · 1.3 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
#!/bin/bash
# Prompt user for operation
echo "Do you want to encrypt or decrypt? (E/D)"
read op
if [ "$op" == "E" ]; then
# Encrypt
echo "Enter path to file or folder:"
read path
echo "Enter passphrase:"
read -s passphrase
if [ -f "$path" ]; then
# Encrypt file
echo "$passphrase" | gpg --symmetric --yes --batch --cipher-algo AES256 --passphrase-fd 0 --output "$path.gpg" "$path"
echo "Encryption successful! Encrypted file saved as $path.gpg"
elif [ -d "$path" ]; then
# Encrypt folder
for file in "$path"/*; do
echo "$passphrase" | gpg --symmetric --yes --batch --cipher-algo AES256 --passphrase-fd 0 --output "$file.gpg" "$file"
done
fi
elif [ "$op" == "D" ]; then
# Decrypt
echo "Enter path to file or folder:"
read path
echo "Enter passphrase:"
read -s passphrase
if [ -f "$path" ]; then
# Decrypt file
echo "$passphrase" | gpg --decrypt --yes --batch --cipher-algo AES256 --passphrase-fd 0 --output "${path%.gpg}" "$path"
echo "Decryption successful! Decrypted file saved as ${path%.gpg}"
elif [ -d "$path" ]; then
# Decrypt folder
for file in "$path"/*.gpg; do
echo "$passphrase" | gpg --decrypt --yes --batch --cipher-algo AES256 --passphrase-fd 0 --output "${file%.gpg}" "$file"
done
fi
else
echo "Invalid operation"
fi