This action might not be possible to undo. Are you sure you want to continue?
Brendan Kidwell firstname.lastname@example.org 22 October 2005 Copyright © 2005 Brendan Kidwell. Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons AttributionNonCommercial-ShareAlike 2.0 License. The information contained in this document is provided as-is. The author shall not be liable for any damages resulting from the use of this information. For the most recent version of this guide, please see my web site if you're not already there.
This guide will show you how to use the free public key cryptography system, GNU Privacy Guard. GPG provides functions to encrypt and decrypt data and to create and verify signatures, using public key cryptography. While GPG is available for many different platforms, including Windows, the instructions given here are somewhat Windows-oriented whereever I had to be specific. Most of my peers use Windows exclusively, and those that don't live in Windows are probably at least familiar enough with Windows to understand what I'm trying to convey in the examples. I make the assumption that you will be using GPG without any add-on enhancements such as WinPT or GPGShell, a couple of graphical front-ends. GPG front-ends are nice, and they save you from having to remember the specific syntax of each command, but sometimes they aren't available, and it's important to have a working knowledge of the underlying system. Users who will be routinely sending and receiving encrypted email will want to find an email program that is tightly integrated with GPG, or has a direct plugin that provides access to GPG. In this guide, I will show you how to use the most important GPG commands. GPG has many commands and some commands have quite a few variations. Most GPG commands and options have single-letter abbreviations. For the sake of clarity, these short versions will not be used in this guide. For detailed information on all the commands and options available, see the GPG manual, available on the GPG web site, or in the file gpg.man which is included with the software.
I will assume that you know your way around Windows and its Command Prompt. If you need some help there, check out the hints in the end of Appendix A before you continue. Please note that when I tell you to perform an operation on the command prompt, I assume you have switched to the folder where the files relevant to the discussion are located.
2. Installing GPG
GNU Privacy Guard is available for free from www.gnupg.org for a variety of operating systems, including Windows, Linux, many other flavors of Unix, and Mac OS X.
2.1 Installing in Windows
Note that if you have Cygwin (a suite of software that gives a Windows machine much of the functionality of a Linux machine) you may already have GPG installed. Try running
at the command prompt. If the system says ´Bad command or file name ,´ then you don't have GPG and you must install it. To install GPG on your computer, first go to the GPG web site and download the Windows package from the Downloads page. Look for the ³version compiled for MSWindows´ under ³Binaries´. The file you download will be a self-extracting archive. Run it and follow the prompts. Finally, edit your PATH environment variable so that Windows knows where to find the program. In Windows NT/2000/XP, you will find this under the Control Panel System Properties the Advanced tab Environment Variables System variables. In Windows 95/98/ME, you will find it in the c:\autoexec.bat file. Values in this variable are separated by semicolons, so add GPG's path to the end of the variable. For example, if your PATH variable reads as
then change it to
c:\windows;c: \utils;c:\Program Files \GNU\GnuPG
(Note: ´c:\Program Files \GNU\GnuPG ´ is where the installer places GPG by default. If you chose to install it in an alternate location, make sure you get it right in your PATH variable.) Now you need to make that PATH change effective. If you're using Windows 95/98/ME, restart your computer; if you are using Windows NT/2000/XP, simply start a
At the command prompt. ZIP.) Once you have sha1sum ready. AES256. RSA -E. First. The GPG site has a copy available here: ftp://ftp.2 Installing in Other Operating Systems Installation in Unix-like operating systems is fairly well covered on GPG's web site²in fact. AES192.) The point of this exercise is that we are verifying that no one has tampered with your download of the GPG installer. BZIP2 2.3 Verifying Your GPG Download Several people have asked me if it's possible to verify the authenticity of the GPG download.gnupg. if you wish to take every available security precaution. without using GPG itself to do the verifying. they might have tampered with sha1sum. This program comes with ABSOLUTELY NO WARRANTY. (Use Google to find a site that has a mirror of it.4. Inc. RSA-S. 2. TWOFISH Hash: MD5. Download this file and put it somewhere convenient. AES. open a command prompt window and go to the folder where you downloaded the GPG Zip file. and close any command prompt windows you had open. SHA1. BLOWFISH. SHA384. DSA Cipher: 3DES. See the file COPYING for details. you need to get a copy the program called sha1sum. Home: C:/Documents and Settings/KidwellB/Application Data/gnupg Supported algorithms: Pubkey: RSA.2 Copyright (C) 2005 Free Software Foundation. SHA256. this can be done.org/gcrypt/binary/sha1sum. and then I make sure utils is in the PATH environment variable (as explained above. SHA512 Compression: Uncompressed. ELG-E. type gpg --version and you should see something like the following output: gpg (GnuPG) 1. so you don't have to worry about explicitly installing it. Now you should be all set to go. Type something like the following command: .fresh command prompt. You can put it in your system32 folder under your Windows folder.exe as well since they both reside on the same FTP server. RIPEMD160. most Linux distributions come with GPG prepackaged. Now try it out. ZLIB. and you are welcome to redistribute it under certain conditions. This is free software. CAST5. If someone tampered with that. This is a useful thing to do if you downloaded GPG from some local mirror and you want to be sure no one's tampered with it.exe But you should try to find it elsewhere. I prefer to put such utilities in their own separate folder called c:\utils. See Further Reading for more information. Yes.
Creating Your Personal Key Pair GPG uses public key cryptography for encrypting and signing messages. What you really need is a really good source for a random string of words.1 About Key Security When you create a key pair. you must have a cryptographically strong passphrase²something that can't be guessed or brute-force attacked. In order for this system to work. this is what GPG does. because anyone who can gain access to your private key can decrypt your messages and impersonate you.sha1sum gnupg -w32cli-1.2. one above the other. prompts you for your passphrase.2. it will have a different name. go back to the GPG web site and find the page called ³Integrity Check´ in the ³Download´ section.) 3. (Hint: These SHA-1 sums are big numbers. If a new version has been released. even if you could memorize it. The practical solution to this problem is to go a step further and actually encrypt your private key using a reasonably short passphrase as a key for the key.) sha1sum will respond with a hash value. For example. GPG reads the encrypted key from the disk. This creates a security risk. then congratulations²you have a valid copy of GPG. Public key cryptography involves your public key which is distributed to the public and is used to encrypt messages to be delivered you and to decrypt signatures you have created. .exe (Be sure to specify the actual name of the GPG installer file you downloaded. Now.exe Make a note of that number. these are referred to as a key pair. like this: 8394920be8d2daa764e94d4bd5869853a3f293b8 *gnupg -w32cli-1. it would take too long to type it out each time you wanted to use it. ³orange´ is so short that a dictionary attack will find it in seconds. Together. Each time you perform an operation involving your private key. and your girlfriend's full name is a poor choice because anyone who knows you might guess that you used it as your passphrase. You can't commit your private key to memory and erase it from your computer²it is far too long (usually at least 1024 bits²that's like memorizing a 300-digit phone number!) Besides. 3. At the bottom of the page. To make it easier to compare them. decrypts the key in memory. and finally uses it.4.4. If the number matches. you should find ³SHA1 Sum Summary´ which should include a number for the file you just ran through sha1sum. you might try copying yours and the one from the GPG web site into a text editor. and your private key which complements your public key by allowing you to decrypt messages you receive and to encrypt signatures. both your public and private keys must be stored on your computer.
1) After you enter and . Again. the author of Diceware recommends you repeat this entire process five times. 3. say you rolled 3. is that everyone you correspond with must fetch your new key when the old one expires. not just yours. or select ³key does not expire. GPG will not give you any feedback as you type your passphrase²it won't print asterisks or spaces as most password input functions do. If you don't feel comfortable attaching your full real name to your key. ³DSA and ElGamal. The best solution is said to be gambling dice and a word list.2 Diceware You might try using your computer to generate a random string of words for your private key passphrase.´ If your key is too small. Finally.´ Now you enter the Real Name and Email Address which will be used to identify the key in everyone's key collections. to produce a five-word passphrase. with digits ranging from 1 to 6 instead of 0 to 5²perfect for looking up numbers randomly generated by the roll of a die. The tradeoff. of course. it is easier to crack. you're ready to generate your personal key pair. At the prompt.5. type gpg --gen-key GPG responds with a menu asking what kind of key pair you want to generate.6. enter the passphrase you generated using Diceware. be sure to pick something unique so that your key won't be confused with anyone else's. Choose the default. but that's generally also a bad idea because computers are theoretically incapable of producing truly random numbers. ³ladle. This is yet another security measure. if it is too large. because documents encrypted after this time are not connected with the old key in any way. The procedure is fairly simple. choose the default of ³1024.´ and record that.) Now roll the a die five times and record the results. For example. You would find word number 35623 in the word list. Download the word list from the Diceware web site and open it in a text editor (such as Notepad. For a reasonable compromise between ease of memorizing your passphrase and security. The next prompt asks you when (if) the key should expire.3. indexed by a five-digit base 6 number.2. it asks you the size of the key. then every operation that uses it may execute too slowly. Look up that number in the word list and write down the word that corresponds to it.3.3 Using the GPG Gen-key Command Now that you've got your passphrase. choose a reasonable time period for the lifetime of your key.´ Next. The author of the Diceware wordlist compiled a text document containing about 8000 short words. such as Diceware. Letting the key expire after a certain amount of time adds a little bit of security. At the command prompt.
2. This makes it easy to copy and paste the key to and from web pages and email messages.then confirm your passphrase. The ´-armor ´ option applies to most GPG commands that produce any kind of output. at least) subject to manin-the-middle attacks. type some random characters on the keyboard. The exchange of public keys without a trusted intermediary can be subject to a man-in-the-middle attack. Open the output file. You should see something resembling this:3) -----BEGIN PGP PUBLIC KEY BLOCK ----Version: GnuPG v1. YOUR-NAME can be your Real Name or your Email Address.txt. including console input²so if you want to speed up the process. which are beyond the scope of this guide. Of course. The ´ --armor ´ option instructs GPG to format the output ³armored´ for plain-text transmission. To transmit your public key over the Internet.txt" --export "YOUR -NAME" You may change key. Type gpg --armor --output "key.4 Publishing Your Public Key The easiest way to publish your public key is to simply post it on a web page or email it directly to people who need it. this is also one of the least secure ways of doing it²plaintext email and web pages can be (theoretically. the first step is to export it to ASCII format. GPG will find it either way. It uses all sorts of sources inside the computer to simulate randomness. key. GPG will start doing some number crunching to generate all the random bits it needs in your key pair. 3. you may be comfortable with the method described here. Open a command prompt window and go to a folder where you want to place the exported key.txt to some other filename if you'd like.2) More advanced methods of key exchange involve things such as webs of trust and key servers. You have been warned.1 (MingW32) mQGiBD53m34RBAC6GXvDFWD3a+GOkQKubz5Koq9lks9d+gel29/sA5kqSfQnoaeR qdTKLlB+oNsVjDX/Szfi3fsrK5zmKKZVHv3JO4DkxtABf4HgfaGkpav2PvXevYoB YWSGTclHOHN5D3xsbIX6wvunkNhllcqrFlC3braG2tQnt2+PMk1gMA2jhwCg7qam RtC27n0RY25jMfM/fESTImcD/1OtFwRtchqjPvl2IHSCBlltJyksuStevOfAFnc1 p3H+JqdUiKVf8oAF4NP4KarXL34xPCJXLKlBwHC3SH8powy2HX0mhsCjvVQQeLOP fU3Q5DJxGM16hfmqlD1k4a7NUjnXwlCrce4rVToFbCnLrJTVoMDyNhowrXPbP CVM N3FNA/0Uciz19raTBGkwo6kpsicpZG7Mk4eGFK5ssWxPxlLYoQ7yzgekWd9h6zBT IQpdkatzdNf7xDEaUEBhO4vD7Il02OLigro95N5savsH9StTNCsJgmaiwtX5hxuF WpW974xgfCmbGOPnbs1QTuyT85VllLxHI5fsGOYKCd/qo8H4nLQHQksgVGVzdIhZ BBMRAgAZBQI+d5t+BAsHAwIDFQIDAxYCAQIeAQIXgAAKCRDCVd5vH6A96m7fAKDs YVhdSqNn+u/rkj1pU6kFldY0JwCcCCXth72RJ9tAIz5gq9M3m6y2+7q5AQ0EPneb gRAEAIb/sxLIAKaahBfBpGxpn3ZKhvug1z6yP7jLWFNLFugaakYjm5LXsI5Hpj06 mAE2fJPUNc1of0ZaK4La3XA8l/nVaadDP6FDqnxuPv3ne5JAxcK76ecT+m0lj QXZ oVnUkUqeNnwtcIs0fmmXnaeD68OHdidYsIuuEDhrFvPAT6cfAAMFA/923B1Bm4NR riLy8QxYNuTxImtxoVg4NtfnYuHWyoxP1Ic3C1nZD2+fxf2685KNKx+3ZwaE81zN ZNl0kNdFhB24Vmr6HM5C+eSlHj8C+LOUdP1A/9Un5utceg/qjNYkRXJx5mjyCizh Gg/+1mLB5e+OA9Tl5R+96PKPFov+UjNPu4hGBBgRAgAGBQI+d5uBAAoJE MJV3m8f oD3qewYAoNFRCBVfbX+LKxmWOZoqyQhB7jfnAKDDOCzQhZLZmrf0Uqdk6yj+HDm0 rA== . If you don't believe specifically that someone will try to attack you.
acquires that recipient's public key if he hasn't already done so.´ This is useful for backup or for transferring it to another computer. That's all it takes to export your public key.. as long as you know what you're doing and you can be sure the new copy will be secure.´ and paste them on a web page or in an email message to someone else. Encrypting and Decrypting Files The basic encryption and decryption procedure in GPG is this: The sender determines the recipient of a file.´ not ´PRIVATE .1 Using the GPG Encrypt Command .) and copy them to a safe location. One important use of GPG is to encrypt your own data. the sender and recipient aren't always different people. 4. and then runs the plaintext through GPG along with this key to obtain the ciphertext. secring. your keys are safe long as your attacker doesn't know your passphrase. and trustdb. Make sure you don't ever accidentally publish your private key! Before you publish a key in ASCII form. with the ´--exportsecret-keys ´ instead of ´--export .) Now. If your key file is destroyed.g pg (They are in C:\Documents and Settings \[your name] \Application Data\gnupg by default. you are finally ready to actually encrypt something. In other words: plaintext + recipient's public key ciphertext and ciphertext + recipient's private key plaintext In fact. (Of course. This is an excellent defense against physical attacks on your computer or your local file server.=+DfK -----END PGP PUBLIC KEY BLOCK ----- Copy the entire contents of that file. check that the first line has the word ´PUBLIC . 4) When the recipient wants to decrypt the file. including all your private keys. 4. he applies his private key to the ciphertext to obtain the plaintext. Note: it is possible to export your private key in the same manner. To back up your GPG keys. locate the files pubring. storing the ciphertext and destroying the plaintext.5 Backing Up Your Keys Keeping your GPG key files safe is just as important as remembering your passphrase² your passphrase does you no good if you don't have a copy of your full private key on your computer. Store this disc in a safe place where potential attackers won't likely be able to find it.´ 3. including the lines beginning with ´----. such as a CD-R disc. there is absolutely no way to reconstruct it.gpg . short of executing a cryptanalysis on your own data.gpg .
txt. 4. You can look at it with Notepad if you'd like.gpg" --encrypt "diary 2003 -02.jpg. As an example.zip.2 Using the GPG Decrypt-Files Command Now. and you're done with February 2003. but a more common use of GPG is to send encrypted data to someone else. Before you can use GPG to encrypt a file for someone else. did you?) you will get back the original plaintext exactly as it was before you encrypted it. you need to get their public key. For example. Suppose you named the saved file brendan. suppose a year from now you're feeling nostalgic and you want to read February 2003's diary. Now diary 2003 02. If you want to decrypt a short file and display it immediately in the console. two convenient ways of getting someone's public key are email and personal web pages.´ which will automatically choose and name an output file for you. and type the following at the command prompt: gpg --decrypt-files "diary 2003 -02. But the filename it chooses will be missing the extension of the plaintext filename (. etc. notice that the command (usually an action verb) always goes in the last position on the GPG command line.1 Importing the key As I said before.3 Sending an Encrypted File by Email Encrypting your own files is useful. There is a similar command.gpg will contain a seemingly random string of bytes. . At the command prompt.) so I don't use it. if you omit this option. Finally. after any options.Choose a file you want to encrypt. Copy all the text you see and paste it into a text file using Notepad. you can download my public key from my web server. 4.txt. Go to my public key page. 4. myself.3. let's assume you have diary. .txt. and you still remember your passphrase (you didn't write it on a Post-It and stick it on your monitor. where each month is a new file. ´--encrypt-files .txt" Don't forget to fill in YOUR-NAME with the actual name you attached to your key. Suppose you want to encrypt this file and then put it away in an archive folder or a CD-R disc.txt. type . You would copy the ciphertext back to your workspace on your computer.txt.gpg" GPG will look up your private key and prompt you for the passphrase. the output will be dumped to the command prompt window instead of to a file. try it right now.txt. Always remember the ´--output ´ option when you use an encryption command in GPG. type (all on one line) gpg --recipient "YOUR -NAME" --output "diary 2003 -02. which is called diary 2003-02. you can use the ´--decrypt ´ command instead of the ´--decrypt-files ´ command. Provided your private key is still installed on your computer. At the command prompt.
2 Encrypting the message Now you're ready to encrypt the file. It looks for the telltale ´BEGIN PGP PUBLIC KEY BLOCK ´ line and ignores everything outside that block of text.´ Then enter ´quit ´ to save your change.txt. whose content you can copy and paste into an email.gpg" --encrypt "FILE" and instead of pasting FILE.gpg --import "brendan. try emailing yourself.txt" GPG will produce a file calle message to brendan. include it as an attachment.net>" imported gpg: Total number processed: 1 gpg: imported: 1 Notice that GPG wasn't distracted by all the extra text on the page. At the command prompt.txt. (See Section 3.gpg into the body of the email. Let's assume you have a file you want to send to me called message to brendan. Instead of emailing me. type gpg --armor --recipient "Brendan Kidwell" --output "message to brendan. then from that computer send an encrypted message to yourself and receive it on your first one and see if you can decrypt it. GPG is paranoid. 4. You can setup another computer and only give it your public key.txt" GPG should say gpg: key A3CA0378: public key " Brendan Kidwell <email@example.com" --encrypt "message to brendan. use the GPG ´--edit-key ´ command to set the trust level: gpg --edit-key "Brendan Kidwell" GPG will enter the interactive key editing mode. and if you use the key right now as it is. you will get a warning message saying that you haven't established the authenticity of the key.txt. Alternatively. [2007-03-02] This section used to have an invitation to try sending an encrypted message to me. but I don't personally use GPG much anymore.4 for instructions on how to export your public key so you can install it on the other computer. you should use the encrypt command without the ´--armor ´ option: gpg --recipient "RECIPIENT" --output "FILE. so I never have it ready when someone sends me a GPG-encrypted message.) . I'm sorry. if you need to send a particularly large file. One more step you need to perform after you've imported a key from an external source is set the trust level on it. Make sure the name of the file doesn't reveal anything that should be secret. To make this warning message go away.asc .3. Enter the command ´trust ´ and select level ³5) I trust ultimately.
though. and end the file name with . type gpg --decrypt-files "FILE.asc extension. If you know that the encrypted data is some binary format. GPG give up and tell you that it doesn't have the private key needed to decrypt this file.asc.4 Decrypting Files Sent by Email How you deal with an encrypted email message which you have received depends on how it was sent to you. Or the message might simply have an attached file whose name ends with ´. its body might contain -----BEGIN PGP MESSAGE ----- followed by a string of random-looking characters. minus the . you would name the file message.gpg" where FILE. save the entire message to a file. For example. but this can get tiring if you need to send a file to many people. GPG will only work if you have the private key needed to decrypt the file. At the command prompt. if you know the message contains an encrypted Microsoft Word file. If the encrypted data is in an attached file.. you can display it on the console instead of storing it in a file with the ´--decrypt ´ command: gpg --decrypt "FILE.. GPG will tell you who the file was encrypted for and prompt you for the passphrase. .. if you know the encrypted data is just a short text message.4. save that file to your computer.) Again.asc" 4. because no one should be sharing a private key with anyone else. If the decryption succeeded.asc . include the file extension before the . When you receive an encrypted message.5 Encrypting for Multiple Recipients Sometimes..4. If the encrypted data is in the message body.4. Remember. This could create a problem.2 If encrypted data is in an attached file. You could always make a separate encrypted file for each recipient. with the name you gave it. you should get the original file back. you'll want to send an encrypted file to more than one person.doc. At the command prompt. (If the message was created using PGP.1 If encrypted data is in the message body.´ 4.pgp ´ instead.asc" where FILE.5) the name of the attached file will probably end with ´.gpg ´ or ´.asc .asc is the filename you used to save the message.pgp. 4.gpg is the name of the file you saved. type gpg --decrypt-files "FILE. If the file wasn't encrypted using your public key.
GPG's signature functions provide a means of verifying authenticity. I tried encrypting a large (~8MB) compressed binary file for one and then two recipients.2 above. or at least approve of its contents in some way (depending on the nature of the actual data. If you specify your target and yourself as recipients when you prepare an encrypted message. You would type the following at the command prompt: gpg --armor --recipient "Brendan Kidwell" --recipient "YOUR -NAME" --output "message to brendan. and arguably. and appends it to the original data as the signature.) You can always go back and review your sent email to recall what was said. This makes it possible to create signed files that are .3. The syntax is straightforward.asc" --encrypt "message to brendan. Signing Files Often it is desirable to verify the origin of data. then you can go back and review it in your sent email collection whenever you need to. Normally when you send plaintext email. The difference in the size of the output was only a few hundred bytes. Public and private GPG keys work either way. Once you have encrypted data with one of the keys in a pair. whether it is encrypted or not. Instead. Normally GPG operates by encrypting with the public key so that only the recipient can decrypt the data using his private key. nor do you need to make another copy encrypted for yourself.) A digital signature is just as useful as a physical one made with a pen. Suppose you wanted to encrypt the same message as in Subsection 4. Sending encrypted email this way can make it easier to manage your saved correspondence. it computes a hash value. it doesn't encrypt the entire file with the signer's private key.6) encrypts that. GPG will then use all of those individuals' public keys to encrypt the data in such a way that any one of their private keys (and no one else's) can decrypt the data. Specifying several recipients does not adversely affect the size of the encrypted data.txt. data is encrypted using the signer's private key. then presumably. a copy of the sent message is saved somewhere in your email software (unless you specified that you don't want to save copies. the signer must have created the data himself. with only the added step that you need to decrypt it before you view it. but wanted to send the message so that both you and I could decrypt it later.txt" and then copy the output file into an email message as before.There is a better way: GPG allows you to specify a list of people who may be able to decrypt a file. Therefore. Just add more ´--recipient ´ options to the command line. it can only be decrypted with its complement in a the same key pair. The theory is simple. Digital signatures work the other way around. it is more secure. You needn't save a separate plaintext copy of the message. When GPG creates a digital signature. the data must have been encrypted by that signer. If someone receives the file and succeeds in decrypting the data with the signer's public key. 5.
txt . GPG will compute a signature and write a new file called message. here is message that I have signed: -----BEGIN PGP SIGNED MESSAGE ----Hash: SHA1 This is a test message signed by Brendan Kidwell.txt. you need to obtain the signer's public key and install it on your computer.) Then type the following at the command prompt: gpg --verify "message. To verify a signature. Before you can verify its signature. This procedure is described in the previous chapter. The contents of this file can be copied into an email and sent to the intended recipient. and use it to check the signature and report whether or not it is valid.1 Using the GPG Clearsign Command Suppose you want to send a message to someone in such a way that they can prove it was you who authored the message. GPG is needed only to verify the authenticity of the file. First.txt" Since this operation involves your private key.1 (MingW32) iD8DBQE+fnwc4lxlBKPKA3gRAq13AJ4557Md6xF15OoEDyIIB+UvDQKwmwCfcrCY na12Ng9W4K5mP1ZWEueNjCo= =73hB -----END PGP SIGNATURE ----- 5. and aren't significantly larger.txt in a convenient folder. compose the message in a text editor and save it as message. Then it decrypts the signature.2 Verifying a Clearsigned Message Suppose you receive a message like the one produced in the previous section. save it as a text file (named. Then.2. If the two hash values match. Or you might find such a message posted on a public web site or electronic message board. 5.´ If the message to be verified is contained in an email.asc containing the plaintext and the signature. GPG will prompt you for your passphrase. export it to a text file. If the message is displayed on a web page or some other online medium.readable without any encryption software. GPG reads the data that was signed and computes its hash value. at the command prompt. under the heading ³Importing the key. using the signer's public key. After that. for example.asc" GPG will locate the signer's key if you have it. As an example. to obtain the true hash value. the signature is valid and the data you have is exactly the data the signer had when he created the signature. . type gpg --local-user "YOUR -NAME" --clearsign "message. -----BEGIN PGP SIGNATURE ----Version: GnuPG v1. message.
zip. the person doing the verifying must have a the signer's public key installed.sig" GPG will verify the signature of the file using the signer's publ ic key and report whether or not it is valid.zip" Again. you can try copying the test message displayed in the previous section into a text file and verifying the signature with this procedure. but binary files such as Microsoft Word documents and Zip archives can't have arbitrary data attached to them. Use this command to encrypt and sign a file: gpg --local-user "YOUR -NAME" --recipient "RECIPIENT" --armor --sign --output "FILENAME. GPG will prompt you for your passphrase and then it will generate a signature in monthly report. Suppose you have a Zip archive you want to sign. simply run gpg --decrypt-files "FILENAME.asc . 5. Type the following at the command prompt: gpg --local-user "YOUR -NAME" --output "monthly report.If you're reading the online version of this document and you've already installed my key. Now suppose you're on the other end and you receive a file with a signature like this via email. which need not be trusted. Again. it is costumary to have GPG create a separate signature file.sig . After the download is complete. Software distributed over the Internet is often signed in this manner²especially software that relates to security. called monthly report.zip. you would attach both files to the email message.3 Signing and Verifying Binary Files Text messages can have signatures appended to them without disrupting the contents of the message too much. Save both files to the same folder and type the following at the command prompt: gpg --verify "monthly report.sig" --detach-sign "monthly report.asc" . If you were going to email this to someone. To sign binary files. To decrypt such a file.asc" --encrypt "FILENAME" This produces an output file named FILENAME. he can go back to the creator's web site and fetch a public key and the signature for the installation package and use them to verify the package's authenticity.zip. 5.zip . A user can download a large installation package quickly from a local site.4 Encrypting and Signing at the Same Time It is possible to encrypt and sign a file at the same time.
On a Windows machine. All you have to do is copy the main executable file. but a major disadvantage of the FTP protocol is that it has very little security. this is a hidden folder called . you should tell GPG to use a different folder for its home folder. file are transferred over an unencrypted channel. this is C:\Documents and Settings \[your name] \Application Data\gnupg. with a small amount of effort. Suppose you want this application to be able to send updates to a central location.GPG will see that the file has been signed and it will automatically verify it if it has the signer's public key. 6.1 Preparing a Minimal Copy of GPG As a software developer. as always if you prefer simple binary output. Whenever GPG runs. on a Unix machine (or a Windows machine with GPG installed under Cygwin). This chapter will explain how to modify your program so that it can use GPG. One solution to this problem is to include GPG with your program. Which keys you install will depend on what GPG functions your application will use. and use GPG to encrypt the data before it is sent. ´ option tells GPG to use the current folder as its Home Directory. And.gnupg which is a subfolder of the home folder of the current user. To prepare your application's special copy of GPG. Suppose you have created a data entry application which will be installed on several client's machines. type gpg --homedir . 6. you will have to install the necessary public and private keys into it. to your program's own folder and prepare it correctly. it assumes all of its keys are located in the Home Directory. When your application calls its own special copy of GPG. Suppose you want your application to be able to send encrypted files to a user named Administrator. At the command prompt.txt and copy that text file into your application's folder. Sending the data over the Internet to an FTP server would be a convenient way to do this. This isn't necessary. --import "administrator. in your application's folder. At the command prompt. such as the folder where your application and GPG are located. type gpg --homedir . you probably don't want to require your client to install GPG by himself and then import the necessary keys. Don't forget to set the trust on the key you just imported. --edit-key "Administrator" .txt" The ´--homedir . gpg. Integrating GPG into Your Programming Project GPG can be integrated into an existing programming project.exe . omit the ´--armor ´ option. Export Administrator's public key to a text file called administrator.
It would then use the operating system to call GPG with the following command (being sure to execute it in the application's own folder): gpg --homedir .dat. ´ ftp>. it should package it up in some convenient way into a single file.script >ftp. If you will have more than one user uploading data to you. to upload a file from within your application.gpg" --encrypt "update_user001. you can type ´ftp´ and you will get a prompt saying. Suppose your application exported its data to a file called update_user001. --recipient "Administrator" --output "update_user001. your application should run the following command: ftp -s:ftp.gpg ´ and you will want to send it to your FTP server. Suppose you put these commands in a file called ftp.3 Calling the FTP Command from Your Application At this point.log .gpg quit Needless.dat. you would have to replace the words in all-caps with the actual values that belong there.´ 6.dat. you should ensure that each one uses a unique filename to avoid name collisions on the FTP server. you need to create a script file with the following lines: open HOSTNAME user USERNAME PASSWORD cd /DESTINATION -FOLDER bin put update_user001.´ then ´5. you will have an encrypted file named ´update_user001.dat" 6.Enter ´trust. You would want to run this script and capture the output to a log file so your application can examine it to see if the file transfer was successful.´ The basic commands inside FTP are as follows: open hostname Open a connection to hostname user username Initiate login process ls List contents of current folder cd folder name Change to a different folder bin Set binary mode for file transfer get filename Download file put filename Upload file quit Exit FTP So.´ then ´quit. At the command prompt.2 Calling GPG from Your Application When your application is ready to send data. To do this.dat . Windows has a convenient console-mode FTP command that supports rudimentary scripting.script .
but you have been warned. which is actually a part of the private key. you must store the passphrase on the computer. free for all to see. It is very important that the message being scanned for in the log file actually appears there if the transfer was successful.log for signs of success or failure. If the message does not appear. My reasoning behind that statement is straightforward: All of security protocols built into GPG depend on the passphrase. of course. . If you are trying to write a decryption script that requires no user intervention. That may or may not be a valid stance to take. go to my web site and download the demo application and try it out. my program assumes the transfer failed and displays an error message. don't be afraid to download this demo application and take a peek.4 Demo Application I have created a Microsoft Access application that demonstrates the secure data transfer scheme outlined above. 6. which makes your private key vulnerable. There is an option in GPG that specifies that the required passphrase be read from a particular file handle. Even if you've never programmed Microsoft Access before. Programming in Microsoft Access is done in the Visual Basic language. The way I do this is I read the entire file into a string variable and then search that string for the words 226 Transfer complete. and the source code is embedded in the database file.5 Decrypting Files Automatically Several readers have asked me about how to have an automated script decrypt files. Exact details of where to look inside the demonstration application can be found in the application's readme file. with the opportunity for the user to inspect the log file himself. is that whenever you perform a command involving a private key (decrypting or signing) GPG stops to prompt you for the passphrase on that key² assuming that key is properly installed. it is virtually impossible to crack the security and make use of the private key. which is always the standard input stream. As long as the passphrase is not known.Then your application should search the contents of the file ftp. 6. (with that exact capitalization). The problem. It's probably safest (in terms of stability) to use file handle 0. That having been said. The option is ´--passphrase -fd´ and it is followed by the number of the file handle. There is no fully secure way to get around this prompt and make the script run without user interaction. instead of from the keyboard. You should verify that this is exactly what your FTP server will say when a transfer is complete. If you have Microsoft Access. I'm sure there are many people who aren't very concerned about the security of their local files.
In edit (4) mode.) Alternatively. Each character between that first space and the pipe is sent to GPG as part of your passphrase. specifies that Windows should take the standard output (which is normally directed at the display) of the first command and pipe it into the standard input (normally the keyboard) of the second command. (Unix/Linux users: use the cat command instead of type. |.txt (3) gpg --import "KEY.txt gpg --edit-key "NAME" Edit the key for NAME.) The pipe character. but no space before the pipe character. without saving it to a separate file on disk: echo PASSPHRASE| gpg --passphrase -fd 0 OPTIONS COMMAND Make sure that you have a single space after the echo command.Suppose you have prepared a file called passphrase which contains the passphrase required for a particular operation. Someone might be able to retrieve the passphrase from whatever part of your program generates the above system call. there might be a way to snoop the data as is passes from your program. use the ´trust ´ command to set the trust level (4) gpg --recipient "RECIPIENT" --output "F ILENAME. Be aware that this really isn't any safer than saving the passphrase in a file on the disk. you would substitute OPTIONS and COMMAND with actual GPG instructions. GPG Cheat Sheet A. you can use the echo command to send the passphrase to GPG. Put the following line in your script: type passphrase | gpg --passphrase -fd 0 OPTIONS COMMAND (Of course.txt" Import the keys found in KEY.1 GPG Commands Relevant chapter numbers in the full guide are displayed in parentheses after each item. gpg --version Find out what version of GPG you have installed (2) gpg --gen-key Create a new key pair (3) gpg --armor --output "KEY.txt" --export "YOUR -NAME" Export your public key to a text file KEY.gpg" --encrypt "FILENAME" Encrypt FILENAME using RECIPIENT 's public key (4) . Appendix A. Many other attacks are possible as well. through echo to GPG.
2 The Windows Command Prompt X: Switch to drive letter X cd FOLDER -NAME Switch to the folder ³FOLDER-NAME´ cd \ Go to the root folder of the current drive cd .asc " or gpg --decrypt-files "FILENAME. SOME -COMMAND Use the current folder as the home folder.gpg" --encrypt "FILENAME" Encrypt a file and output text suitable for email (4) gpg --decrypt-files "FILENAME.sig" --detach-sign "FILENAME" Create separate digital signature file for FILENAME (5) gpg --verify "FILENAME.asc" --encrypt "FILENAME" Encrypt and sign FILENAME . Go to the parent folder of the current folder dir List the contents of the current folder exit Close this command prompt window .asc (5) gpg --homedir .sig (5) gpg --armor --local-user "YOUR -NAME" --recipient "RECIPIENT" --sign --output "FILENAME.sig" Verify the digital signature for FILENAME contained in FILENAME. with text output to FILENAME. useful for calling GPG from an application..asc (5) gpg --verify "FILENAME.gpg output to FILENAME (4) verify a digital signature if present. and gpg --local-user "YOUR -NAME" --clearsign "FILENAME" Create digital signature and output plaintext plus signature to FILENAME. (6) A.asc or FILENAME.asc" (5) Verify the digital signature found inline in FILENAME.gpg --amror --recipient "RECIPIENT" --output "FILENAME.asc gpg --local-user "YOUR -NAME" --output "FILENAME.gpg" Decrypt FILENAME.
including The GNUPG Mini-Howto and The GNU Privacy Handbook. Updated Section 2. Moved ³History´ to the end of the document. (It was previously distributed as a Zip file you had to extract and install manually.com .org .4. Further Reading and Exploration If you're reading this document on paper.keyserver.glump. you will find some useful documents. www. contains the word list for choosing truly random passphrases as mentioned in the ³Creating Your Personal Key Pair´ chapter.man .2 Removed Section 2.) Updated some sample output to reflect cosmetic changes as of GPG version 1. Updated installation instructions to reflect GPG's new automatic installer. included with GPG.Appendix B.net/content/gpg_intro My example Microsoft Access application that demonstrates how to call GPG from inside another program can be found at www. The installer takes care of this for you.gnupg. The Diceware web site. Document History 22 October 2005 y y y y y y y y y Converted to dokuwiki format to integrate it into my new web site.1. Moved most URLs in the text into hyperlinks on actual text²new printer style sheet puts URL references next to hyperlinks. Discontinued PDF version. I found a decent tutorial for the Windows command prompt called ³How to use an MSDOS Prompt window´ at www. www. .glump.com/tutorials/msdos/ . don't forget to check out the online version to see if it's been updated: www. In the ³Documentation´ section of this site. It is very informative on the subject of key security.diceware.net is a good free public key directory service that a reader pointed out to me.3 because the distribution of GPG is verified by SHA instead of MD5 now.net/content/accessgpgdemo GNU Privacy Guard's main web site is located at www.1 about installing GPG in an alternate location.c3scripts. I also recommend that you check out the FAQ on that web page. don't forget that the syntax of all of GPG's commands is given in detail in the file gpg. Most importantly. Changed the license to Creative Commons.
1. added a link to GPGShell. Added Section 4. suppose Eve wants to intercept a message Alice will send to Bob. Added some more info in Further Reading appendix. and finally sent on to Bob±with no one the wiser. it would take a very determined attacker to pull this off in practice. Achilleus. Clarified the fact that the public key displayed in Section 3. Fixed error in Section 2. Added Section 2. reencrypted with Bob's real public key. 20 October 2003 y y y y y y y y Changed many example commands for encryption. throughout the guide. where I specified that you should export the downloaded Zip archive to a folder named gpg²it should have been gnpug. 31 March 2003 y 1) Initial release. 2) A man-in-the-middle attack would involve a third party replacing the public key before the person who wants it tries to retrieve it.3.5. Needless to say. Fixed a typo where I was talking about the ³version´ option in Section 2. to avoid the loss of the plaintext's filename extension. decrypted by Eve's private key and read. an attacker might be able to observe how many characters are in your passphrase by looking over your shoulder. ³Encrypting for Multiple Recipients. which is intercepted by Eve.´ 23 August 2003 y y y A handful of grammatical errors and related issues were fixed. ³Verifying Your GPG Download.8 November 2003 y y y Made many minor corrections thanks to the help of my Greek translator. Alice uses this key to encrypt and send a message to Bob.5.´ Fixed a typo in Section 3. This security measure will make it harder for someone to gain any information about your passphrase. In the Introduction. ³Decrypting Files Automatically. Changed the title of Chapter 6 from ³Integrating GPG into Your Application´ to ´«Your Programming Project´ to make it clear that non-programmers need not read this chapter.´ Added Section 6. next to the one for WinPT. For example. If GPG gave you feedback with asterisks. Bob publishes his real public key on his web site and Eve immediately breaks in to the web server and replaces the key with her own fake public key for Bob. Sorry about the mess in the previous version. Fixed the syntax of the command given in the section called Encrypting and Signing at the Same Time. .1. but is in fact Eve's replacement.4 a lot of people complained about: changed exportsecretkeys to export-secret-keys. Alice downloads what she believes to be Bob's public key.4 should not be used to encrypt messages to me.
see "Hash Function" in Wikipedia. hash functions used in cryptology must be very sensitive to small changes in the data. Actually. the words plaintext and ciphertext don't necessarily refer to simple text. An ideal hash function works only one way. an image. plaintext can be absolutely any block of data. my public key is available at on my web site. As it says in section 4. the hash value will be different. 6) A hash value is a relatively short string of data that represents a large string. but it is incredibly difficult to find a data set that will produce a given hash value. Also. 5) PGP is a commercial software tool that implements of the same algorithms and protocols used in GPG. GPG descended from PGP. A hash function computes the hash value of a string of data. and have whose passphrase I have long ago forgotten. For more information.3. 4) In this context. such as a text. 3) . so that you can be sure that if someone changes the data.The public key displayed here is not my public key. It happens to be a key I created for my GPG talk at school. sound. it is easy to compute a hash value of a given data set. or video.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.