Encrypt / Decrypt Files with GPG Encryption

?
R
Bash

Useful to lock down SSL Certificates, SSH Keys, Sensitive Information, etc.. GPG relies on the idea of two encryption keys per person (private & public). The public key can decrypt something that was encrypted using the private key. To send a file securely, you encrypt it with your private key and the recipient’s public key. To decrypt the file, they need their private key and your public key. Public keys must be shared. https://www.howtogeek.com/427982/how-to-encrypt-and-decrypt-files-with-gpg-on-linux/

1# Simpler version
2gpg --encrypt --sign --armor --recipient x.x@a.io secrets.tar.gz
3
4
5# Pack files
6tar -czvf secrets.tar.gz ./secrets
7
8# Encrypt and Decrypt message (me and John)
91. First we must have John's public key.
10gpg --import john.key
11
122. Encrypt a tar.gz and send it to John
13gpg --encrypt --sign --armor --recipient gen@coderecipes.org --recipient xpto@email.com configmaps.tar.gz
14
153. Inspect encrypted file
16less configmaps.tar.gz.asc
17
184. Decrypt
19gpg --decrypt configmaps.tar.gz.asc > configmaps.tar.gz
20
215. Send it to John! 
22et voilà
23
24
25
26# Method 2
27# macOS install gpg
28brew install gnupg
29
30# generate a key
31gpg --gen-key
32
33# tar ball the folder
34tar czf vault.tar.gz mydirectory/
35
36# encrypt the tarball
37gpg -e -r Claudio vault.tar.gz
38
39# remove the tarball
40rm -rf vault.tar.gz
41
42# decrypt the gpg
43gpg -d -o vault.tar.gz vault.tar.gz.gpg 
44
45# troubleshoot (osx)
46gpgconf --kill gpg-agent

Created on 12/27/2017