Skip to content

Instantly share code, notes, and snippets.

@krescruz
Created February 1, 2018 23:37
Show Gist options
  • Save krescruz/e3c2b52f5729dfb2e51143457eeefa2c to your computer and use it in GitHub Desktop.
Save krescruz/e3c2b52f5729dfb2e51143457eeefa2c to your computer and use it in GitHub Desktop.
Encrypting files using GNU Privacy Guard (GnuPG or GPG) - Command line example
import sys
import gnupg
def main():
path_home = sys.argv[1]
path_file_input = sys.argv[2]
path_file_output = sys.argv[3]
gpg = gnupg.GPG(gnupghome=path_home)
key = gpg.list_keys()
with open(path_file_input, 'rb') as file:
encrypted = gpg.encrypt_file(file, recipients=key.uids,
always_trust=True, output=path_file_output)
if not encrypted.ok:
raise encrypted.stderr
if __name__ == "__main__":
main()
@krescruz
Copy link
Author

krescruz commented Feb 1, 2018

Command line example

krescruz@localhost:~$ encryp_file_gpg.py "/path/home/gpg" "path/file/input.txt" "path/file/out.txt.gpg"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment