Chapter 4
72
Password-Based Encryption (PBE)
The examples that we've given so far have used binary keys. These keys need to be stored in some fashion
on a hard drive or floppy disk for instance. Password-based encryption (PBE) uses a password as the key.
This is convenient because the security then rests with the user rather than in a physical medium.
Unfortunately, password-based encryption in general isn't as secure as algorithms with binary keys like
TripleDES or Blowfish. To demonstrate this, let's say we use Blowfish with a key size of 128 bits. That gives
us a keyspace of 2128. Password-based encryption typically uses ASCII characters. An average user's
password might be 6 characters in length. If it's entirely lowercase, there are only 266 possible keys, or
roughly 228. Adding capital characters and symbols helps quite a bit, but it cannot even approach the
keyspace of a good symmetric algorithm.
To add to their insecurity, most passwords are simple everyday words. If an attacker were trying to crack a
password, they would likely try every English word, which could be done rather quickly on a fast computer.
This is known as a dictionary attack and is surprisingly successful. There are a number of tools out there
that will automate a dictionary attack some even test combinations of words, differing capitalization, and
the use of numbers and some symbols. It's quite interesting to try one of these tools out and see how secure
a password is. A good password should be at least 8 characters long and use capitalization, numbers, and
symbols, like "m1Nnes0+a". It's important that the password be simple enough to memorize, however, as
you should never write a password down.
Password encryption uses a combination of hashing and normal symmetric encryption. The password is
hashed using a message digest algorithm like SHA-1 (we'll discuss this topic more in Chapter 6), and then
the resulting hash is used to construct a binary key for an algorithm like Blowfish as shown in the following
diagram:
Message
Digest
Symmetric
Cipher
Password
Hash
Plaintext
Message
Ciphertext
Used as key
As we mentioned, one of the problems with password-based encryption is that it is possible to create a
precompiled list of passwords, hash them, and have a set of keys ready to try on encrypted data. This
allows an attacker to try all normally used keys very quickly, and so determine if any of them decrypt the
data. There are two techniques used to combat this attack: salting and iteration counts. A salt is a random
value appended to the password before it is hashed to create a key, and the iteration count is the number of
times the salt and password are hashed. Let's examine each of these in some detail and see how they
improve security.