Adding encryption and decryption

This commit is contained in:
Alex Epstein 2017-06-26 21:03:40 -04:00
parent b273d23d77
commit 0410f65b19
7 changed files with 79 additions and 10 deletions

View File

@ -42,6 +42,17 @@ Converts currency based on realtime exchange rates
</div>
## Encryption & Decryption
A wrapper for openssl that allows for quickly encrypting and decrypting files
<div align="center">
<img max-height="500px" max-width="500px" src="https://github.com/alexanderepstein/Bash-Snippets/blob/master/crypt/crypt.png?raw=true">
</div>
#### To Be Added
[ ] Pass in arguments as well on top of the option to have it guide you through input

41
crypt/crypt Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# Author: Alexander Epstein https://github.com/alexanderepstein
encrypt()
{
openssl enc -aes-256-cbc -salt -a -in $1 -out $2 || { echo "File not found"; exit 1; }
echo "Successfully encrypted"
}
decrypt()
{
openssl enc -aes-256-cbc -d -a -in $1 -out $2 || { echo "File not found"; exit 1; }
echo "Successfully decrypted"
}
while getopts ":e:d::" opt; do
case $opt in
e)
if [[ $# -gt 3 ]]; then
echo "Option -e only accepts two arguments" <&2
exit 1
fi
encrypt $2 $3
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
d)
if [[ $# -gt 3 ]]; then
echo "Option -e only accepts two arguments" <&2
exit 1
fi
decrypt $2 $3
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

BIN
crypt/crypt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

6
crypt/install.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# Author: Alexander Epstein https://github.com/alexanderepstein
echo -n "Installing crypt: "
chmod a+x crypt
cp crypt /usr/local/bin > /dev/null 2>&1 || { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; }
echo "Success"

5
crypt/uninstall.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/bash
# Author: Alexander Epstein https://github.com/alexanderepstein
echo -n "Removing crypt: "
rm -f /usr/local/bin/crypt > /dev/null 2>&1 || { echo "Failed" ; echo "Error removing file, try running uninstall script as sudo"; exit 1; }
echo "Success"

View File

@ -1,10 +1,13 @@
#!/bin/bash
# Author: Alexander Epstein https://github.com/alexanderepstein
cd currency
cd currency || exit 1
./install.sh || exit 1
cd ..
cd stocks
cd .. || exit 1
cd stocks || exit 1
./install.sh
cd ..
cd weather
cd .. || exit 1
cd weather || exit 1
./install.sh
cd .. || exit 1
cd crypt || exit 1
./install.sh

View File

@ -1,10 +1,13 @@
#!/bin/bash
# Author: Alexander Epstein https://github.com/alexanderepstein
cd currency
cd currency || exit 1
./uninstall.sh || exit 1
cd ..
cd stocks
cd .. || exit 1
cd stocks || exit 1
./uninstall.sh
cd ..
cd weather
cd .. || exit 1
cd weather || exit 1
./uninstall.sh
cd .. || exit 1
cd crypt || exit 1
./uninstall.sh