Created
May 3, 2018 19:31
-
-
Save fcaldarelli/07ed8861fe2e6834afdfd0682610a69b to your computer and use it in GitHub Desktop.
Hybrid symmetric-asymmetric encryption for large files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####### 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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment