-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt_decrypt_item.sh
More file actions
executable file
·96 lines (79 loc) · 3.31 KB
/
encrypt_decrypt_item.sh
File metadata and controls
executable file
·96 lines (79 loc) · 3.31 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
#!/usr/bin/env bash
# Description: script that has functions to encrypt or decrypt a file or item.
#############################################################################################
# NOTE: you are going to have to create a pub_key.pem and a priv_key.pem file using openssl #
# look up how to do it on google #
#############################################################################################
# function to encrypt
encrypt()
{
# prompt for user input
read -p "Provide an item to encrypt: " ITEM
if [[ "${ITEM}" ]]
then
# command to encrypt user's input
openssl pkeyutl -encrypt -inkey pub_key.pem -pubin -in "${ITEM}" -out "${ITEM}.enc";
# command to rename encrypted item (removes the .enc extension)
mv "${item}.enc" "$(ls ${ITEM} | cut -d "." -f 1).enc";
else
# display message
echo "Error couldn't encrypt ${ITEM}." 2>&1;
# exit script with error
exit 1;
fi
}
# function to decrypt
decrypt()
{
# prompt for user input
read -p "Provide an item to decrypt: " ITEM1;
if [[ "${item_1}" ]]
then
# command to decrypt user input
openssl pkeyutl -decrypt -inkey priv_key.pem -in "${ITEM1}" -out "${ITEM1}.dec";
# command to rename decrypted file (removes the .dec extension)
mv "${ITEM1}.dec" "$(ls ${ITEM1} | cut -d "." -f 1).dec";
else
# display message
echo "Error couldn't decrypt ${ITEM}." 2>&1;
# exit script with error
exit 1;
fi
}
# prompt for user input
read -p "Do you want to encrypt or decrypt a file? (encrypt/decrypt): " ANSWER;
# if statement to check for user's input
if [[ "${ANSWER}" = 'encrypt' ]]
then
# call encrypt function
encrypt;
elif [[ "${ANSWER}" = 'decrypt' ]]
then
# call decrypt function
decrypt;
else
# display message
echo "please provided and appropriate answer: (encrypt/decrypt): ";
fi
#############
# my banner #
#############
##########################################################
# source: http://patorjk.com/software/taag/ #
##########################################################
echo -e "\nScripted by: ";
echo -e "\n";
echo -e "\033[0;5m";
echo " ██▓ ██████▄▄▄█████▓▄▄▄ ▄████▄ ██ ▄█▒███████▒";
echo "▓██▒██ ▒▓ ██▒ ▓▒████▄ ▒██▀ ▀█ ██▄█▒▒ ▒ ▒ ▄▀░";
echo "▒██░ ▓██▄ ▒ ▓██░ ▒▒██ ▀█▄ ▒▓█ ▄▓███▄░░ ▒ ▄▀▒░ ";
echo "░██░ ▒ ██░ ▓██▓ ░░██▄▄▄▄██▒▓▓▄ ▄██▓██ █▄ ▄▀▒ ░";
echo "░██▒██████▒▒ ▒██▒ ░ ▓█ ▓██▒ ▓███▀ ▒██▒ █▒███████▒";
echo "░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ▒▒ ▓▒█░ ░▒ ▒ ▒ ▒▒ ▓░▒▒ ▓░▒░▒";
echo " ▒ ░ ░▒ ░ ░ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░░▒ ▒ ░ ▒";
echo " ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░░ ░░ ░ ░ ░ ░";
echo " ░ ░ ░ ░ ░ ░ ░ ░ ░ ";
echo " ░ ░ ";
echo -e "\033[25m";
echo -e "\n";
###########################################################