GPG/PGP Free Data Encryption with Python

2020-09-11に共有
In this video, we will encrypt and sign documents with PGP and Python as part of my series on encryption with Python.

Specifically, we are going to use GnuPG or GPG, which is essentially a free version of PGP and is part of the OpenPGP standard

First of all….PGP or Pretty Good Privacy.

PGP was developed in the early nineties by Phil Zimmerman. Phil offered up the source code for PGP which was used to develop the Open PGP ..a standard for

GPG encrypts data using asymmetric key pairs that are individually generated by users. GPG also supports symmetric encryption with AES and other algorithms …but we’ll leave that discussion for another day.

If you remember, In the world of asymmetric encryption , each user has a key pair …one public and one private key. There is a mathematical relationship between each key pair where you can encrypt with one and decrypt with the other.

How this typically works is that Bob securely sends Alice his public key. Alice encrypts a file with Bob’s public key and sends it to Bob, knowing that only Bob can decrypt because he has the private key that was associated with the public key he sent to Alice.

GPG has several command line options to manage your encryption but we are going to use a Python library instead called python-gnupg

To exchange encrypted files in GPG, each user will need to have GPG installed on their computer. Also, we will need to install the GnuPG libray in python to write the code.

コメント (21)
  • @spit9243
    thanks for making this video! you just solved my problem in 5 minutes, been banging my head against the wall for days.
  • Thanks this video inspired me to write a short program in python to encrypt digital assets. I opted to manually import the public key I tested with. Excellent demonstration of code that was easy to adapt and implement.
  • This video is very comprehensive, and an excellent way to gain an understanding of PGP, and public key cryptography as a whole. I'm hoping this channel receives a lot of attention, because it's a joy to see this depth of coverage when it comes to a subject like this, and I feel everyone should be aware of the ins and outs. It helps enhance all of our security. By the way, thank you for replying to my suggestion!
  • This should get me started using GnuPG. Nice introduction, great video!
  • @kewei4767
    Thank you so much for the video. If there is one video that sums up all the basics of GPG it would definitely be this!! 😄
  • Anyone had any success running this on a windows machine? I'm not sure what my gnupghome directory should be. I was able to get gpg to work via command line in wsl, but I can't seem to find the .gnupg dir in windows. Is there another download I need to perform to work outside wsl?
  • When I am trying to encrypt the file I am getting AttributeError:'GPG' object has no attribute 'encrypt_file'. could please tell me I am getting this error I am doing same approach.
  • Thank you for the video! It is a really nice introduction to working with PGP/GPG. I tried to generate keys but could not seem to make it work, tried it without the input "key_lenght = 2048" and it worked after that. Any idea how come?
  • What could be the possible vulnerabilitys/holes from incorrect configuration?
  • Encryption part is not working I am getting attribute error encrypt_file is not found i am seeing please help me here
  • @helo1345
    So when we're importing bob's public key I keep getting an error code 2 and google seems to think this is due to the public key being unsigned. I'm on Windows which is probably making this harder. Any advice?
  • I keep getting this error on windows when i run gpg = gnupg.GPG(): " _find_binary raise RuntimeError("GnuPG is not installed!")" I am able to encrypt files using gpg.exe from cmd line. Anyone know what might be causing the error?
  • Thanks for the nice explanation, is it possible to split the encryption based on size(for example if the file size is more than 1 GB split in 2 files) and then compress it zip.gpg?
  • why I am getting decrypted_data.valid is False decrypted_data.trust is None