GnuPG Hacks
Want to encrypt a file, but don't know where to start? Here's a quick and clean introduction to file encryption using GnuPG:
$ gpg -c test.txt Enter passphrase: Repeat passphrase:
When encrypting, GnuPG asks for a passphrase twice, just like when you set a new password. The new encrypted file has the same name, but with the extension .gpg added. The original file is left intact.
The -c stands for conventional encryption, also known as symmetric encryption. Normally, GnuPG defaults to public key encryption, but we haven't generated or loaded any public keys, so for now we have to stay with conventional.
This type of encryption is most useful only if you want to decrypt your files, but you don't trust where your files are stored. For example, easily lost or stolen storage can be protected with this type of encryption. This type of encryption is especially useful for off-site backups.
To extract the encrypted file, simply type:
$ gpg filename.gpg
GnuPG automatically detects that the file is encrypted with a passphrase and asks for that passphrase. Then it writes the decrypted data to a file with the same name but without the .gpg extension. As with encrypting, the encrypted file is left intact. If you want the output file to be written to a different filename, use standard redirection, exactly as with the --dearmor example. Note that both input and output redirection must be used, or GnuPG becomes confused:
$ gpg < filename.gpg > filename.txt
If you want someone else to decrypt the file, you have to tell this person the passphrase without leaking the passphrase to anyone else. A simple and straightforward way to do this is in person. That might seem not very useful, as the original file also could be given in person. But that passphrase can now be reused safely multiple times on different files in the future. Just like passwords, however, passphrases should be changed regularly. Never reuse a passphrase with other people, unless you want them to decrypt all of the files you ever encrypted with that passphrase.
Note: this warning is normal when using passphrase encryption in GnuPG. This can be avoided with public key encryption:
gpg: WARNING: message was not integrity protected
The passphrase is a secret that keeps the other secrets, which makes it the most important part of GnuPG security. Unfortunately, in practice, passphrases are also the weak part. This is because creating good passphrases is difficult, and remembering them is even more difficult.
I highly recommend Diceware, but if it doesn't appeal to you, take a look at the Wikipedia article (see Resources) or the passphrase Web pages recommended by your favorite Web search engine.
Regardless of what method you choose, a simple guide to passphrase security is that longer is usually better (Table 1).
Table 1. Password and passphrase strengths compared with estimated time to crack.
| Type | Length | Bits | Total Bits | Time to Crack |
|---|---|---|---|---|
| Single word of any language | 8 characters | 24 | 24 | Seconds |
| Random mono-case letters | 8 characters | 4.7 | 37 | Minutes |
| Random mono-case letters | 16 characters | 4.7 | 75 | Decades |
| base64 [A-Za-z0-9+/=] | 10 characters | 6 | 60 | Months |
| base64 [A-Za-z0-9+/=] | 20 characters | 6 | 120 | Uncrackable? |
| Completely random printable | 6 characters | 6.5 | 40 | Minutes |
| Completely random printable | 8 characters | 6.5 | 52 | Hours |
| Completely random printable | 12 characters | 6.5 | 78 | Decades |
| Completely random printable | 15 characters | 6.5 | 97 | Centuries |
| Completely random printable | 20 characters | 6.5 | 130 | Uncrackable? |
| Diceware passphrase | 2 words | 12.9 | 26 | Seconds |
| Diceware passphrase | 4 words | 12.9 | 51 | Hours |
| Diceware passphrase | 6 words | 12.9 | 78 | Decades |
| Diceware passphrase | 8 words | 12.9 | 120 | Uncrackable? |
The time estimates in Table 1 are wide, because money and time can be traded evenly. Computing power keeps getting cheaper, so time to crack keeps getting shorter. Cracking costs start at free and go up.
If you cannot remember a GnuPG passphrase, the data encrypted with that passphrase is probably gone forever. There are no known back doors in GnuPG nor any way to recover a lost passphrase short of guessing. How long it takes depends on how good the passphrase was. A good 20-character passphrase could take billions of years to guess, even using all current and future computers.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- Dart: a New Web Programming Experience
- Developer Poll
- What's the tweeting protocol?
- May 2013 Issue of Linux Journal: Raspberry Pi
- Reply to comment | Linux Journal
4 hours 13 min ago - Reply to comment | Linux Journal
5 hours 41 sec ago - Web Hosting IQ
6 hours 34 min ago - Thanks for taking the time to
8 hours 11 min ago - Linux is good
10 hours 8 min ago - Reply to comment | Linux Journal
10 hours 26 min ago - Web Hosting IQ
10 hours 56 min ago - Web Hosting IQ
10 hours 56 min ago - Web Hosting IQ
10 hours 57 min ago - Reply to comment | Linux Journal
13 hours 57 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




Comments
wrong correction?
> The stdin (file descriptor 0) of the gpg process is filename txt,
rather than passphrase.txt, so your (intended) passphrase is never actually used!
Then how come the decryption worked?
I like this article
i've been using GPG for a few years, and never knew about the --enarmor option (it isn't even in man page for version 1.2.6. I also like the built-in RNG, which I never knew existed. I enjoyed this tutorial did not include information about public key crypto, which is much more common on the web. That makes this article (and ones like it) in shorter supply == more valuable.
Thanks!
GPG should not be used here
GPG should not be used here at all. According to the man page, the input password is not even hashed.
Have a look at aesloop instead. (Or maybe openssl enc alternatively)
gpg --passphrase-fd 0 doesn't do what you think it does
The following command, as given in the article, has a problem.
cat passphrase.txt | gpg --passphrase-fd 0 -c < filename.txt > filename.gpg
The stdin (file descriptor 0) of the gpg process is filename txt,
rather than passphrase.txt, so your (intended) passphrase is never actually used!
Use this instead:
gpg --passphrase-fd 3 -c 3<passphrase.txt < filename.txt > filename.gpg
You failed to spot the problem simply because the decryption command
has the same problem...
(The unescaped less-than character in my 2 previous posts seem to have caused problems.Please delete them/ignore them)
gpg --passphrase-fd 0 doesn't do what you think it does
The following command, as given in the article, has a problem
cat passphrase.txt | gpg --passphrase-fd 0 -c < filename.txt > filename.gpg
The stdin (file descriptor 0) of the gpg process is filename txt,
and not passphrase.txt, so your (intended) passphrase is never actually used!
Use this instead:
gpg --passphrase-fd 3 -c 3 < passphrase.txt < filename.txt > filename.gpg
You failed to spot the problem simply because the decryption command
has the same problem...