How to encrypt and decrypt with PGP

14

PGP performs a very powerful position in encrypting and decrypting the information. Techniques comparable to hashing, public-key cryptography, and knowledge compression are all used in PGP encryption. By the usage of “GPG” or “GnuPG” which is loose signing and encryption device in line with PGP, you’ll be able to export, import private and non-private keys, and in addition encrypt and decrypt information. The GPG key pair incorporates two kinds of keys: Private and Public keys. You can use the general public key for encrypting the information, and that encrypted information will likely be decrypted the usage of the name of the game or non-public key of the receiver.

The process of encrypting and decrypting information with PGP incorporates some easy steps. Firstly, the sender has to export your public key and ship it to the receiver. Then, the receiver will import the general public key in its keyring. After this, the receiver can encrypt any record using the general public key of the sender. On the opposite hand, the receiver will then decrypt the shared record the usage of its non-public key.

This write-up will information you about learn how to encrypt and decrypt with PGP. From exporting and uploading public keys to encrypting and decrypting information, step by step directions will likely be equipped for each and every process. So, let’s get started!

Note: We have already generated two GPG keypairs for the demonstration goal, one for “john” and the opposite for “fred” on two separate techniques. Now, we can export john’s public key, after which import it at the different device.

How to export public key with GPG

Before sending your public key to a correspondent, you need to export it first the usage of the gpg command. In the gpg command, an extra argument is specified for figuring out the general public key which would be the consumer ID in our case, and to generate the output of the exported record in ASCII structure the “-a” or “–armor” possibility is added within the “gpg” command.

To export a selected public key, to start with, listing out the generated GPG keys to your device and choose the important thing which you wish to have to export. To accomplish that, execute the below-given “GPG” command:

For example, for exporting the general public key of the consumer “john” we can notice down its consumer ID “uid” from the listing:

To export the general public key of “john” we can upload the “–export” possibility within the GPG command. Here, the “-a” possibility is applied for developing an ASCII illustration of the general public key, and the “>” redirect operator is used for redirecting the output of the GPG command to the “public.key” record:

$ gpg –export -a john > public.key

Here the “.key” extension signifies that the encrypted content material is provide within the required record:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459211 156 How to encrypt and decrypt with PGP

The error-free output announces that our “public.key” record is all in a position to export. To take a look at its content material, execute the next “cat” command:

As you’ll be able to see, the “public.key” has saved the ASCII illustration of john’s public key:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459212 736 How to encrypt and decrypt with PGP

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459213 241 How to encrypt and decrypt with PGP

Till this level, we have now created a record “public.key” that incorporates the ASCII illustration of the general public key of “john”. Now, we can percentage this record with every other device consumer, in order that the “newuser” can import the GPG key to its keyring.

How to import public key with GPG

With the GPG command, uploading public key for your keyring is so simple as exporting them. By uploading the general public key of the sender, you’ll be able to decrypt the gained encrypted information, paperwork, or emails.

The earlier segment confirmed the process to export john’s “public.key”. Now, we can information you concerning the process of uploading it on every other “newuser” account. Before uploading the “public.key”, we can listing out the keys provide within the newuser’s keyring:

Currently, “newuser” has best the GPG keypair for “fred” uid, which will also be noticed within the following output:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459213 419 How to encrypt and decrypt with PGP

Now, to import the loo’s “public.key”, we can execute the “gpg” command with the “–import” possibility:

$ gpg –import public.key

The below-given output is appearing that the general public key of “john” is imported effectively:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459214 617 How to encrypt and decrypt with PGP

For the affirmation of the required operation, we can listing out the “newuser” Public keyring:

John’s public key’s imported effectively which will also be noticed within the below-given symbol:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459215 832 How to encrypt and decrypt with PGP

How to edit the important thing consider worth with GPG

After uploading john’s public key to the “newuser” keyring, we can set its consider worth which is “unknown” at this level:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459215 647 How to encrypt and decrypt with PGP

You can execute the next gpg command for modifying the consider worth of john’s public key:

$ gpg –edit-key john public.key

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459215 177 How to encrypt and decrypt with PGP

Now, kind “trust” and hit “Enter” to take a look at the consider menu choices:

Here, we can input “5” to be sure that we consider john’s public key “ultimately”:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459216 846 How to encrypt and decrypt with PGP

Exit from the gpg modifying window by means of writing out “quit” and press “Enter”:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459217 953 How to encrypt and decrypt with PGP

Again, listing out the “gpg” keys and take a look at the consider worth of the “john” key:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459217 105 How to encrypt and decrypt with PGP

How to encrypt record with GPG

On the “newuser” device, we have now a record named “encryptfile1.txt” which we’re going to encrypt with john’s public gpg key. Before transferring in opposition to the encryption process, we can display the content material provide throughout the specified record:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459217 123 How to encrypt and decrypt with PGP

To encrypt a record the usage of the gpg command, observe the below-given syntax:

$ gpg -e -u [Sender_uid] -r [Receiver_uid] [Filename]

Here, the “-u” possibility is applied for specifying the uid of the sender and “-r” for the recipient. The sender’s secret key and the receiver’s public key’s used for encrypting the record.

Now to encrypt the “encryptfile1.txt” with the fred’s secret key and john’s public key, we can write out the next command:

$ gpg -e -u fred -r john encryptfile1.txt

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459218 627 How to encrypt and decrypt with PGP

The error-free output announces that an encrypted record is generated effectively. To verify this motion, we can listing out the content material of the present listing:

The output displays that the “encryptfile1.txt.gpg” is created for our decided on record:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459218 335 How to encrypt and decrypt with PGP

Check out the “encryptfile1.txt.gpg” content material by means of executing the “cat” command:

$ cat encryptfile1.txt.gpg

The encrypted content material of the “encryptfile1.txt.gpg” will likely be proven within the terminal:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459219 891 How to encrypt and decrypt with PGP

Now, percentage the encrypted record with the meant recipient over the e-mail or the usage of another supply.

How to decrypt record with GPG

The “-d” possibility is added to the “gpg” command to decrypt the encrypted record. In our case, we have now shared the “encryptfile1.txt.gpg” with the “linuxhint” consumer, which owns john’s GPG key pair. Now to decrypt the gained record, we can kind out this command:

$ gpg -d encryptfile1.txt.gpg

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459219 72 How to encrypt and decrypt with PGP

You will likely be requested to go into the “Passphrase” to liberate john’s secret key. Write the passphrase within the enter box and click on at the “OK” button:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459219 715 How to encrypt and decrypt with PGP

After coming into the right kind passphrase, the required record will likely be decrypted, and its content material will likely be displayed at the terminal:

how to encrypt and decrypt with pgp How to encrypt and decrypt with PGP 1641459219 380 How to encrypt and decrypt with PGP

Conclusion

PGP encryption is utilized by maximum firms for exchanging information comparable to information, paperwork, and emails over the web. It secures delicate data from being misused thru electronic mail assaults. The private and non-private GPG keys are applied to encrypt and decrypt information. Without a GPG key, nobody can decrypt the information. We have guided you on learn how to import and export your GPG public key. Moreover, the process for encrypting and decrypting information with PGP could also be equipped.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More