Skip to content

Instantly share code, notes, and snippets.

@FreeWall
Created June 20, 2018 13:56
Show Gist options
  • Save FreeWall/d7465366931b9cb623f0f3dcef59fe2e to your computer and use it in GitHub Desktop.
Save FreeWall/d7465366931b9cb623f0f3dcef59fe2e to your computer and use it in GitHub Desktop.
#!/bin/bash
echo -e "===== BACKUP DECRYPTOR =================================="
echo ""
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
file=$1
argkey=$2
privatekey=$dir/backup-key-private.pem
if [ ! -f "$privatekey" ]; then
echo " Private key $privatekey not found!"
else
if [ -f "$file" ]; then
dirkey=$(openssl rand -hex 16)
dirkey=decrypt_backup_$dirkey
mkdir "$dirkey"
tar -zxvf $file -C $dirkey > /dev/null 2>&1
base64 -d $dirkey/encrypted-key.txt > $dirkey/decrypted-key.txt
key=$(openssl rsautl -decrypt -inkey $privatekey < $dirkey/decrypted-key.txt)
if [ "$argkey" = "-key" ]
then
echo " Passphrase of $1"
echo -e " \e[1m$key\e[0m"
else
zipfile=$file
zipfile=${zipfile%.tar.gz}
7za e -y -p$key $dirkey/$zipfile.zip > /dev/null 2>&1
echo -e " \e[1m$file \e[0mdecrypted to \e[1m$zipfile\e[0m"
fi
rm -rf $dirkey
else
echo " File $file not found!"
fi
fi
echo ""
echo -e "========================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment