Hybrid symmetric-asymmetric encryption for large files
####### STEP 1
cd local
openssl genrsa -out keyfile.key 4096
openssl rsa -in keyfile.key -pubout -out keyfile.pub
cp keyfile.pub ../remote/
####### STEP 2 -Encrypt
#!/bin/bash
file=$1
passfile=${file}_pwd
pubkey=keyfile.pub
openssl rand 256 > ${passfile}
tar cz $file | openssl enc -aes-256-cbc -salt -out ${file}.enc -pass file:./${passfile}
openssl rsautl -encrypt -pubin -inkey ${pubkey} -in ${passfile} -out ${passfile}.enc
rm ${file} ${passfile}
cp ${file}.enc ${passfile}.enc ../local
####### STEP 3 - Make it executable:
chmod +x ./encrypt.sh
####### STEP 4 - Copy to local folder
echo "secret data" > testfile
./encrypt.sh testfile
####### STEP 5 - Decrypt
#!/bin/bash
file=$1
passfile=${file%.enc}_pwd.enc
privatekey=keyfile.key
openssl rsautl -decrypt -inkey ${privatekey} -in ${passfile} -out ${passfile%.enc}
openssl enc -d -aes-256-cbc -in ${file} -pass file:./${passfile%.enc} | tar xz
rm ${file} ${passfile} ${passfile%.enc}