Preparing a Minimal Copy of GPG

As a software developer, you probably do not want to make your clients install GPG themselves and then import necessary keys. There is a more comfortable alternative. All you have to do is copy the main executable file, gpg.exe, to your program’s own folder and prepare it correctly.

Whenever GPG runs, it assumes all of its keys are located in the Home Directory. On a Unix machine (or a Windows machine with GPG installed under Cygwin), this is a hidden folder called .gnupg which is a subfolder of the home folder of the current user. When your application calls its own special copy of GPG, you should tell GPG to use a different folder as its home folder, such as the folder where your application and GPG are located.

To prepare your application’s special copy of GPG, you will have to install the necessary public and private keys into it. Which keys you install will depend on what GPG functions your application will use. Most likely, you want your application to be able to send encrypted files to a user named Administrator. Export Administrator’s public key to a text file called administrator.txt and copy that text file into your application folder. In the command prompt, in your application’s folder, type

gpg --homedir . --import "administrator.txt"

The “--homedir .” option tells GPG to use current folder as its Home Directory.

Don’t forget to set the trust for the key you just imported. Type in the command prompt:

gpg --homedir . --edit-key "Administrator"

Enter

trust
5
quit