Today's Question:  What does your personal desk look like?        GIVE A SHOUT

Encrypting and decrypting PGP file or text on MacOS

  sonic0002        2020-10-29 05:06:09       31,404        1    

When doing data exchange among different parties, there is a frequent need of encrypting data or file and sending it to partner and asking partner to use corresponding key to decrypt the data or file. A famous way of exchanging data is using asymmetric keys where no secret key needs to be shared. One party can just use the public key shared by partner to encrypt the data and the other party uses the private key to decrypt the data.

Today, we will introduce how to use PGP to encrypt and decrypt data on MacOS. Pretty Good Privacy (PGP) is an encryption system used for both sending encrypted emails and encrypting sensitive files. 

There are a few software on the internet can be used to do PGP encryption/decryption, on MacOS, we can use GPGTools, It can be easily installed on MacOS, after installing, when launching the tool GPG Keychain, you can generate new key pair or you can import existing keys shared by others or generated by yourself. The key setup is the first step before you can start to encrypt or decrypt data.

In GFG Keychain, if the keys are generated or imported, you would see below:

The type column indicates the key type, if it's a public key, it will tell you it's pub, if it's a private key, it would show as sec/pub.

Now to encrypt some file or data, you can hover on the file and right click mouse/touch pad.

You will find Services and a few options over there. When encrypting file, select OpenGPG: Encrypt File.

It will now ask to you to select recipient, basically the public key to use to encrypt the file. After encryption, a new file named original_file_name.gpg would be created.

When trying to decrypt the file, can do the same by selecting service OpenGPG: Decrypt File. The file will be decrypted with the sec key imported in your keychain. If there is no corresponding secret key can be used to decrypt the file, it would give some error saying no key is available to decrypt. In this case, you need to import the correct secret key.

Apart from decrypting file, one can also encrypt selected data in a file. The approach is similar to file encryption. Open the file, select portion of the data to be encrypted, then right click to bring up the menu, 

The encrypted data will put in the file with below encrypted data:

-----BEGIN PGP MESSAGE-----

hQIMA3h4T1eMIzgjAQ/+Ol7eQFkY4BuU+c4ucoYjate2dzSQcbkuuZXK7heF/pd1
hmJKpdUaw09f+2t4aD/Plw5HUNkEkZU6glkw3jZhLyjQX46RzzHKkjEg3XFM3ovi
GWsA5QfwoDE5iBr94H04GH8hHL7PbvY/Ryrynb2L6ciXh6IB6g3EkS4xSdM4vVZU
gDIfXSZZDmCi6v4HdbJ0LV9gZcZ4qCqnaIxnEurELsXHOqVoUpMxONttfAPStVQD
rzU9KV7LJ4PZw/3CAmYUXp8SrX128jC0nshkh4uKtBCriEPn2HRTiJKJIJXJSYKM
sxahLfAbo/q3DPLrJwggA1WRydY9g7N2HLHO/sF/UuXBCqAx3F8Ed04QeM/9k7Kq
3w9QghsITGu/utNpPQVWRgtv9BGSe0qfR6fspcBhLcelyavcOcAJSMzk95xerNiN
4Li4tiDaGCnndhbMxNZB7UbzmckNKCF16y6XUF3x4XTWVI8HNwAgaeepM22qRzO7
3eIJ7Www/DZl7wQkf+je/D0lX28lOstEXBrLhXoh/i+nsPwP4OO34nOnbpZ6qvjJ
vk7IciAM8zO8WeTVeynyvG4J8Zr59dpZgDyetAse7gHExcTETgjIulm2wNmB5/9J
z0WJG9IUvfEQqqrb8PJ7EoQnVucf3c6hS2gvFvyIP3l9EREqe2v4KFXwsS0a5W3S
RAGdAk5u27TtK2TdQrTsjuF1BUkN3JrH01G9oD5cASBZ3BFU+DOJGpqwdfJ3f5Mu
ZamsTZwmBUJ7025WBvaZeW4AEEVW
=wysv
-----END PGP MESSAGE-----

There are also some other tools can be used. Like PGPTool, a tool written with Java, the UI has a typical Java style looking.

TUTORIAL  DECRYPTION  ENCRYPTION  GPG  PGP 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  1 COMMENT


Anonymous [Reply]@ 2022-07-26 15:42:46

I am performing these steps and get a "Decryption failed: No Data! (No data)
Code = 58" message. Can anyone shed light on how to troubleshoot this? Thank you!