Key Generation 9
For most, this is either too inconvenient or has unacceptable availability implications.
In addition, using protected keys in production does not actually increase the security
much, if at all. This is because, once activated, private keys are kept unprotected in
program memory; an attacker who can get to the server can get the keys from there
with just a little more effort. Thus, passphrases should be viewed only as a mechanism
for protecting private keys when they are not installed on production systems. In other
words, it’s all right to keep passphrases on production systems, next to the keys. If you
need better security in production, you should invest in a hardware solution.
7
To generate an RSA key, use the genrsa command:
$ openssl genrsa -aes128 -out fd.key 2048
Generating RSA private key, 2048 bit long modulus
....+++
...................................................................................…
+++
e is 65537 (0x10001)
Enter pass phrase for fd.key: ****************
Verifying - Enter pass phrase for fd.key: ****************
Here, I specified that the key be protected with AES-128. You can also use AES-192 or AES-256
(switches -aes192 and -aes256, respectively), but it’s best to stay away from the other algo-
rithms (DES, 3DES, and SEED).
Warning
The e value that you see in the output refers to the public exponent, which is set to
65,537 by default. This is what’s known as a short public exponent, and it significantly
improves the performance of RSA verification. Using the -3 switch, you can choose 3
as your public exponent and make verification even faster. However, there are some
unpleasant historical weaknesses associated with the use of 3 as a public exponent,
which is why generally everyone recommends that you stick with 65,537. The latter
choice provides a safety margin that’s been proven effective in the past.
Private keys are stored in the so-called PEM format, which is just text:
$ cat fd.key
-----BEGIN RSA PRIVATE KEY-----
7
A small number of organizations will have very strict security requirements that require the private keys to be protected at any cost. For them,
the solution is to invest in a Hardware Security Module (HSM), which is a type of product specifically designed to make key extraction impossi-
ble, even with physical access to the server. To make this work, HSMs not only generate and store keys, but also perform all necessary operations
(e.g., signature generation). HSMs are typically very expensive.