PGP Encryption — A beginner's guide
Understanding PGP
PGP (Pretty Good Privacy) is an encryption program that can be used to cipher all kinds of files from emails to blocks of text to binary files like audio or images. PGP allows for the use of different encryption algorithms like RSA and DES. However the core idea remains the same; using asymmetric encryption.
Making it Happen
As we discussed earlier, PGP itself is a program. For the purpose of this exercise, we will be using a library in python to utilize PGP’s functionalities. To develop a better understanding of the library, it is a good idea to keep the PGPy documentation handy.
Looking at an Example
Feel free to follow along with this code on my git-hub.
Before we can start encrypting files, we need to generate a key for it. During this process we can define the cipher algorithm which we want to use.
We also have the option of generating keys online through different websites.
The public key is responsible for encrypting messages while the private key, also called a sub-key, is responsible for decryption.
Once the keys have been generated, it is good practice to store them somewhere in a file for safe keeping.
Now we are left with the easy part. First we turn our keys into PGPKey objects. Next we turn our message(text or any other file) into PGPMessage objects. Lastly, we call the public_key.encrypt(msg)
method if we want to encrypt the message or private_key.decrypt(msg).message
method if we are going to decrypt it.
The process of encrypting e-mails is very similar to encrypting regular files. You can perform this as a practice exercise. I would recommend looking at further examples for help.
Happy Ciphering!