Last active
July 12, 2020 22:47
-
-
Save ifnazar/bdee375e3239bcce60b6c5d93d9f274d to your computer and use it in GitHub Desktop.
Bash Encrypt & Decrypt
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
openssl - AES256 | |
´´´´´´´´´´´´´´´´ | |
tar -zcf - ${DIRECTORY} | openssl enc -e -aes256 -out ../secured.tar.gz | |
openssl enc -d -aes256 -in secured.tar.gz | tar -xz -C . | |
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
export GPG_KEYRING=${PWD}/nazar.kbx | |
export GPG_PUBLIC_KEY=${PWD}/pubkey.gpg | |
export [email protected] | |
export GPC_PHRASE=s3cr3t3 | |
export GPG_ENCRYPTED_FILE=/tmp/backup.tgz.gpg | |
CREATE KEYRING | |
''''''''''''''' | |
gpg --batch --generate-key <<EOF | |
Key-Type: RSA | |
Key-Length: 2048 | |
Subkey-Type: RSA | |
Subkey-Length: 2048 | |
Name-Real: nazar | |
Name-Email: ${GPG_EMAIL} | |
Passphrase: ${GPC_PHRASE} | |
Expire-Date: 0 | |
%pubring ${GPG_KEYRING} | |
%commit | |
EOF | |
TRUST KEY | |
'''''''''' | |
for fpr in $(gpg --list-keys --keyring ${GPG_KEYRING} --no-default-keyring --with-colons | awk -F: '/fpr:/ {print $10}' | sort -u); do echo -e "5\ny\n" | gpg --keyring ${GPG_KEYRING} --no-default-keyring --command-fd 0 --expert --edit-key $fpr trust; done | |
ENCRYPT & DECRIPT | |
''''''''''''''''' | |
GPC_PLAIN_FILE=/tmp/foo.txt ## file to encrypt | |
gpg --keyring ${GPG_KEYRING} --no-default-keyring --encrypt --recipient ${GPG_EMAIL} -o ${GPG_ENCRYPTED_FILE} ${GPC_PLAIN_FILE} | |
gpg --batch --yes --passphrase ${GPC_PHRASE} --keyring ${GPG_KEYRING} --decrypt --recipient ${GPG_EMAIL} -o ${GPC_PLAIN_FILE} ${GPG_ENCRYPTED_FILE} | |
ENCRYPT & DECRIPT / PIPE TAR | |
''''''''''''''''''''''''''''' | |
GPC_DIRECTORY=/tmp/my-directory | |
tar -cz ${GPC_DIRECTORY} | gpg --batch --yes --keyring ${GPG_KEYRING} --no-default-keyring --encrypt --recipient ${GPG_EMAIL} -o ${GPG_ENCRYPTED_FILE} | |
gpg --batch --yes --passphrase ${GPC_PHRASE} --keyring ${GPG_KEYRING} --no-default-keyring --recipient ${GPG_EMAIL} -d ${GPG_ENCRYPTED_FILE} | tar xz --directory ${GPC_DIRECTORY} | |
CREATE PUBLIC KEY | |
'''''''''''''''''' | |
gpg --keyring ${GPG_KEYRING} --no-default-keyring --armor --output ${GPG_PUBLIC_KEY} --export ${GPG_EMAIL} | |
gpg --keyring ${GPG_KEYRING} --no-default-keyring --import ${GPG_PUBLIC_KEY} | |
tar -cz aaaa | gpg --batch --yes --keyring /home/ifnazar/Downloads/tt/nazar.kbx --no-default-keyring --encrypt --recipient "[email protected]" -o backup.tgz.gpg | |
gpg --batch --yes --passphrase s3cr3t3 --keyring /home/ifnazar/Downloads/tt/nazar.kbx --no-default-keyring --recipient "[email protected]" -d backup.tgz.gpg | tar xz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment