No video

GPG/PGP Free Data Encryption with Python

  Рет қаралды 26,234

Practical Python Solutions

Practical Python Solutions

Күн бұрын

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.

Пікірлер: 64
@WorldDstroyer
@WorldDstroyer 4 жыл бұрын
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!
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 4 жыл бұрын
Thanks! Really glad you liked it!!!
@antman7673
@antman7673 Жыл бұрын
@@practicalpythonsolutions-b4478 I subscribed on a different video. The first one I saw of your channel. As a subscription can fill up the sub feed with „litter“, a high bar has to be crossed. Your video impressed me. Good learning material calmly delivered. Thx for the public service of offering your expertise.
@simonsentore
@simonsentore 3 жыл бұрын
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.
@spit9243
@spit9243 3 жыл бұрын
thanks for making this video! you just solved my problem in 5 minutes, been banging my head against the wall for days.
@loialbringer
@loialbringer 3 жыл бұрын
This should get me started using GnuPG. Nice introduction, great video!
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 6 ай бұрын
Hi. Sorry for the late reply. Thank you for your great feedback!
@kewei4767
@kewei4767 2 жыл бұрын
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!! 😄
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 6 ай бұрын
Hi. Sorry for the late reply. Thank you for your great feedback!
@patrikpatel7675
@patrikpatel7675 3 жыл бұрын
Thank you for putting this together!
@storageaccountiii8917
@storageaccountiii8917 Жыл бұрын
I did not use it yet but loved it.
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 6 ай бұрын
Hi. Sorry for the late reply. Were you able to use it?
@rahulshukla5033
@rahulshukla5033 2 жыл бұрын
Amazing work✌️
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 6 ай бұрын
Thank you!
@BennyHarassi
@BennyHarassi 3 жыл бұрын
This was so useful thx
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
Glad to hear! Let us know if you need help.
@BennyHarassi
@BennyHarassi 3 жыл бұрын
@@practicalpythonsolutions-b4478 surprisingly enough it worked the first time i ran it (which never happens). you're a great teacher
@user-pj1vc4sc2m
@user-pj1vc4sc2m 6 ай бұрын
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?
@dimitriostsantaridis6140
@dimitriostsantaridis6140 3 жыл бұрын
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?
@azmatalica
@azmatalica 3 жыл бұрын
This is too good for me
@jaydenrohleder1152
@jaydenrohleder1152 3 жыл бұрын
What could be the possible vulnerabilitys/holes from incorrect configuration?
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
Hi Jaden , the biggest risk with pki is the disclosure of the private keys. Not sure of any configuration issues other than not selecting the right key length.
@nirmalr6122
@nirmalr6122 3 жыл бұрын
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?
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
HI - you could get the lenght of the file (len(filename) and split that way. For example if the length was 20000, you could then type filename[:10000] amd filename[100001:]
@sudhakarkothapalli3342
@sudhakarkothapalli3342 2 жыл бұрын
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.
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 2 жыл бұрын
Can you put the line of code that’s generating the error here so we can figure out
@sudhakarkothapalli3342
@sudhakarkothapalli3342 2 жыл бұрын
Encryption part is not working I am getting attribute error encrypt_file is not found i am seeing please help me here
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 6 ай бұрын
Hi. Sorry for the late reply. I am back online and I will create a short in the next few days to answer your question.
@johnmontalbano6027
@johnmontalbano6027 Жыл бұрын
This code isn't working for me in February 2023.
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 Жыл бұрын
How so? What error?
@johnmontalbano6027
@johnmontalbano6027 Жыл бұрын
@@practicalpythonsolutions-b4478 it works fine when I simply use `gpg --encrypt lance.txt` and then `gpg --decrypt lance.txt.gpg` I'm trying to get it in Python, though
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 Жыл бұрын
@@johnmontalbano6027 Hi John, what are you running this on. I went back to the video (been a while) and I see that I did it in Linux (raspberry pi). Is that what you are using?
@helo1345
@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?
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 Жыл бұрын
Try the --allow-non-selfsigned-uid switch in gpg. Is there a user I’d assigned to the public key?
@helo1345
@helo1345 Жыл бұрын
​@@practicalpythonsolutions-b4478 I had to adapt it to Python but this did end up working! Thank you! Now that its imported and it lists when I do gpg --list-keys my code says that its unable to find the key lol Thank you for your help!
@helo1345
@helo1345 Жыл бұрын
@@practicalpythonsolutions-b4478 One more question if you don't mind. IF the versions of PGP are different between two users (says bob was using 1.4.23 and alice was using 2.x) Would that create a lot of problems?
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 Жыл бұрын
@@helo1345 should not have an impact. I haven’t experienced any issue myself
@joestopansky6375
@joestopansky6375 3 жыл бұрын
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?
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
if you run "gpg -h" at the Dos prompt do you get list of commands? Looks like GPG is not installed or corrupted
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
BTW: the actaul code requires the input data - see 4.55 on the video
@joestopansky6375
@joestopansky6375 3 жыл бұрын
@@practicalpythonsolutions-b4478 Thanks for the replies! gpg -h does return a list of commands. I ended up figuring out that I had installed two modules with pip. One was the python-gnupg (which you were demoing in this video). The other was just gnupg. I uninstalled both and then re-installed python-gnupg. Everything is working now. Thanks for these videos, btw! There isn't a ton of content out there for this, so this was a great starting point for me.
@gamelover8260
@gamelover8260 3 жыл бұрын
Hi Jaden, Can we add some subkeys under primary key?
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
>>> gpg = gnupg.GPG(homedir='doctests') >>> alice = { 'name_real': 'Alice', ... 'name_email': 'alice@inter.net', ... 'key_type': 'RSA', ... 'key_length': 4096, ... 'subkey_type': 'RSA', ... 'subkey_length': 4096, ... 'subkey_usage': 'encrypt,sign,auth', ... 'passphrase': 'mypassword'}
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
good question, Jaden -see link below to do that pythonhosted.org/gnupg/gnupg.html?highlight=subkeys
@rahulshukla5033
@rahulshukla5033 2 жыл бұрын
why I am getting decrypted_data.valid is False decrypted_data.trust is None
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 6 ай бұрын
Hi. Sorry for the late reply. I will create a short to answer your question.
@frpforums
@frpforums 3 жыл бұрын
hi . your have same tutorial with pycharm
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
I actually tested each file in PyCharm before switching to the Linux command line. Everything should work if you are using a later version of Python and import the appropriate modules. Let em know if you get an error and I'll look into it but you can download the files from my github repo and copy in to pycharm
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
You want the same tutorial w/ pycharm?
@pratiknimbalkar5697
@pratiknimbalkar5697 2 жыл бұрын
@@practicalpythonsolutions-b4478 yes it would be a great help if we get the tutorial for pycharm especially enc and dec the API request responses
@creonte38
@creonte38 3 жыл бұрын
Very good video, very nice channel too. I saw this video and I remember about Isis Lovecruft, she reports some bugs to gpg and the people gave no answer to her. She fork and did python gnupg, and label it as Pretty Bad Protocol. If you wnat to see this code: github.com/isislovecruft/python-gnupg . Anyway you have my subscription and I will spread around here in Brazil South. Thank you for sharing your didatic explanations with us. You are really good teacher!
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
Interesting. Thanks Ayr, appreciate the feedback. I did see the issue that Lovecruft was addressing but according to the updated version of gunpg ...it has been resolved "There is at least one fork of this project, which was apparently created because an earlier version of this software used the subprocess module with shell=True, making it vulnerable to shell injection. This is no longer the case.
@CheapHomeTech
@CheapHomeTech 3 жыл бұрын
You lost me when you used pip3. My pip/pip3 is a nightmare. I'd like to burn the whole system down. They don't work right or consistently.
@practicalpythonsolutions-b4478
@practicalpythonsolutions-b4478 3 жыл бұрын
pip comes with Python 2.7 and pip3 come with Python 3.x . if you're having trouble with pip , make sure that you are using the version with the version of Python you are using. You may need uninstall and reinstall. You can probably do that easily by reinstaling Python. Either way, check the version first. Pip typically doesn't create too many problems with defaults
Data Encryption with Pycryptodome & AES
10:11
Practical Python Solutions
Рет қаралды 19 М.
👑 Шифруем файлы и пароли аки Царь с GPG и Pass!
26:53
Диджитализируй!
Рет қаралды 72 М.
WHO CAN RUN FASTER?
00:23
Zhong
Рет қаралды 44 МЛН
❌Разве такое возможно? #story
01:00
Кэри Найс
Рет қаралды 2,6 МЛН
黑天使遇到什么了?#short #angel #clown
00:34
Super Beauty team
Рет қаралды 45 МЛН
Please Help Barry Choose His Real Son
00:23
Garri Creative
Рет қаралды 22 МЛН
Creating and Managing a GPG Key Pair
22:34
Nick Janetakis
Рет қаралды 70 М.
Using GPG to encrypt and decrypt a file
18:07
Melvin L
Рет қаралды 78 М.
Using GPG
30:26
Computer and Network Security
Рет қаралды 88 М.
147 How to do PGP encryption and decryption using ssis
23:31
Learn SSIS
Рет қаралды 1,7 М.
How to encrypt and decrypt a file with Python?
19:13
AllTech
Рет қаралды 13 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 354 М.
Basic File Encryption with GPG key pairs!
8:36
Luke Smith
Рет қаралды 135 М.
Professional Data Encryption in Python
11:12
NeuralNine
Рет қаралды 56 М.
WHO CAN RUN FASTER?
00:23
Zhong
Рет қаралды 44 МЛН