Encrypt:
openssl enc -e -aes256 -salt -in file-to-encrypt -out file-encrypted.encrypted
Use this one instead, if base64 is needed (send encrypted file as text on email, or messaging).
openssl enc -aes256 -a -in test.txt -out test.txt.enc
If openssl 1.1
or higher, use:
openssl enc -aes256 -a -iter 1000 -in test.txt -out test.txt.enc
#!/bin/bash
# Encrypt
clear
echo '+--------------------------------------------------------------------+'
echo '|If an encrypted file with same name exists, it will be overwritten. |'
echo '+--------------------------------------------------------------------+'
echo '| REMEMBER YOUR PASSWORD, OR YOU WILL LOSE YOUR DATA! |'
echo '+--------------------------------------------------------------------+'
if [ -z "$1" ]; then
me=`basename "$0"`
echo 'ERROR: Missing parameters. Enter file name to encrypt.'
echo ''
echo 'Usage:'
else
openssl enc -e -aes256 -salt -p -in $1 -out $1.aes
fi
Decrypt:
openssl enc -d -aes256 -in file-encrypted.encrypted -out file-decrypted
Use this one instead, if aes256 and base64 was used.
openssl enc -d -aes256 -base64 -in file-encrypted.encrypted -out file-decrypted
If openssl 1.1
or higher was used, then:
openssl enc -d -aes256 -a -iter 1000 -in test.txt.enc -out test.txt
#!/bin/bash
# Decrypt
clear
echo '+--------------------------------------------------------------------+'
echo '| If a file with same name exists, it will be overwritten. |'
echo '+--------------------------------------------------------------------+'
read -p "Press CTRL C to abort, or any key to proceed..."
if [ -z "$1" ]; then
me=`basename "$0"`
echo 'ERROR: Missing parameters. Enter file name to decrypt.'
echo ''
echo 'Usage:'
echo "$me filetodecrypt"
else
encryptedfile=$1
unencryptedfile="${encryptedfile%.*}"
openssl enc -d -aes256 -in $encryptedfile -out $unencryptedfile
fi