Skip to content

Instantly share code, notes, and snippets.

@pstaender
Last active August 24, 2018 07:59
Show Gist options
  • Save pstaender/cb08324afe8a0a5ad4a72c7269a4611e to your computer and use it in GitHub Desktop.
Save pstaender/cb08324afe8a0a5ad4a72c7269a4611e to your computer and use it in GitHub Desktop.
Crypt and Decrypt gzipped tar files in bash
function tarcrypt {
file=$1
filename="$file.tar.gz.enc"
if [ -f $file ]; then
echo "-> $filename"
tar cz $file | openssl enc -aes-256-cbc -e > $filename
elif [ -d $file ]; then
echo "-> directory $filename"
# display progress
# linux: tar cf - $file -P | pv -s $(du -sb $file | awk '{print $1}') | gzip > big-files.tar.gz
tar cf - $file -P | pv -s $(($(du -sk $file | awk '{print $1}') * 1024)) | openssl enc -aes-256-cbc -e > $filename
fi
}
function tardecrypt {
file=$1
openssl aes-256-cbc -d -in $file | tar xz
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment