Skip to content

Instantly share code, notes, and snippets.

@Alexintosh
Created September 3, 2018 16:28
Show Gist options
  • Save Alexintosh/e6fe2ccb4f5c45d05271865325e9a053 to your computer and use it in GitHub Desktop.
Save Alexintosh/e6fe2ccb4f5c45d05271865325e9a053 to your computer and use it in GitHub Desktop.
AES-256-cbc terminal encryption
#!/bin/bash
#encrypt files with aes-256-cbc cipher using openssl
#encrypt files
if [ $1 == "-e" ];
then
if [ -f "$2" ];
then
openssl aes-256-cbc -a -e -salt -in "$2" -out "$2.aes"
else
echo "This file does not exist!"
fi
#decrypt files
elif [ $1 == "-d" ];
then
if [ -f "$2" ];
then
openssl aes-256-cbc -a -d -salt -in "$2" -out "$2.decrypt"
else
echo "This file does not exist!"
fi
#show help
elif [ $1 == "--help" ];
then
echo "This software uses openssl for encrypting files with the aes-256-cbc cipher"
echo "Usage for encrypting: ./encrypt -e [file]"
echo "Usage for decrypting: ./encrypt -d [file]"
else
echo "This action does not exist!"
echo "Use ./encrypt --help to show help."
fi
# encrypt file.txt to file.enc using 256-bit AES in CBC mode
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc
# the same, only the output is base64 encoded for, e.g., e-mail
openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc
# decrypt binary file.enc
openssl enc -d -aes-256-cbc -in file.enc -out file.txt
# decrypt base64-encoded version
openssl enc -d -aes-256-cbc -a -in file.enc -out file.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment