Gpg4win data encryption and decryption

Gpg4win

I explored asymmetric encryption algorithms and planned to implement them using Mathematica. But, I found the signing process somewhat complex, so I opted to use an existing tool for encryption and signing instead. OpenGPG is a suite of applications for encrypting and verifying messages. It uses the IDEA hashing algorithm for encryption and verification. It can encrypt and sign files, emails, and more. The corresponding software for Windows is GPG4WIN. Here is the information from Wikipedia: GNU Privacy Guard (GnuPG or GPG) is encryption software serving as a GPL-compliant alternative to PGP encryption software. Designed according to the OpenPGP technical standards set by the IETF, GnuPG facilitates encryption, digital signing, and asymmetric key pair generation. The IETF is standardizing the PGP protocol, known as OpenPGP. The current versions of PGP and Veridis’ Filecrypt are compatible with GnuPG and other OpenPGP systems. Funded by the German government currently, GnuPG is part of the GNU Project of the Free Software Foundation and is licensed under the GNU General Public License version 3.

Installation and Certificate Generation

GPG4WIN official website: https://www.gpg4win.org/

After downloading, proceed with the installation, including all additional components.

Gpg4win

Upon installation, open Kleopatra to prepare for certificate generation. Kleopatra is a tool for managing certificates,

Gpg4win

Select “personal OpenPGP key pair” to generate a personal key pair,

Gpg4win

We need to fill out some information before generating the keys, as shown below,

Gpg4win

Click the “Advanced Setting…” button to access advanced settings, where we can select the encryption algorithms,

Gpg4win

After completing this step, we’ll review the settings before finally setting a password,

Gpg4win

This password, combined with the private key, will allow the decryption of ciphertext encrypted with the public key,

Gpg4win

Then, we can get a certificate,

Gpg4win

Certificate Export and Revocation

Exporting certificates is straightforward; right-click on the generated certificate and select “Export Certificates…” to export the public key certificate,

Gpg4win

To deploy the public key certificate on a server, select “Export Certificates to Server…”. However, if it’s not our server, we cannot delete it once deployed, which can lead to information leaks if the key is compromised. Thus, creating a revocation certificate is necessary. This can only be done via the CMD command line,

1
gpg --list-keys

After identifying the certificate ID from the list, generate the revocation certificate with the specified command,

1
gpg --output revoke.asc --gen-revoke ########

Choose the reason for revocation,

  • 0 = No reason specified
  • 1 = Key has been compromised
  • 2 = Key is superseded
  • 3 = Key is no longer used
  • Q = Cancel

Add some description, and finalize with the password. The revocation certificate will be located in the personal directory: %userprofile%,

Gpg4win

Encrypting Data

Encrypting information is relatively simple. If we don’t have the encryption certificate, we first need to import the public key certificate,

Gpg4win

Select the “Encrypt/Sign” option from the menu,

Gpg4win

Choose the file to encrypt or sign,

Gpg4win

Then proceed to select the encryption and the corresponding certificate to complete the encryption process,

Gpg4win

Decrypting Data

Decrypting an encrypted file follows similar steps to encryption. First, import the private key certificate, then proceed with the decryption process,

Gpg4win

Choose the save location and whether the file has a signature,

Gpg4win

Enter the private key certificate password,

Gpg4win

Decrypt successfully,

Gpg4win

Additionally, files can be encrypted directly by right-clicking and selecting the encryption option from the menu.

Summary

Recently, I learned that enterprise QQ can monitor all client operations, similar to some corporate software and malware, which can directly monitor keyboard actions. While I wanted to implement this operation with Mathematica, the issues with binary file reading and control still persist, so it is more reliable to use the most common software for encryption.

PS: GPG4WIN can also be used to encrypt emails, here the LINK for more details.