Blame doc/HOWTO/keys.txt

Packit c4476c
<DRAFT!>
Packit c4476c
			HOWTO keys
Packit c4476c
Packit c4476c
1. Introduction
Packit c4476c
Packit c4476c
Keys are the basis of public key algorithms and PKI.  Keys usually
Packit c4476c
come in pairs, with one half being the public key and the other half
Packit c4476c
being the private key.  With OpenSSL, the private key contains the
Packit c4476c
public key information as well, so a public key doesn't need to be
Packit c4476c
generated separately.
Packit c4476c
Packit c4476c
Public keys come in several flavors, using different cryptographic
Packit c4476c
algorithms.  The most popular ones associated with certificates are
Packit c4476c
RSA and DSA, and this HOWTO will show how to generate each of them.
Packit c4476c
Packit c4476c
Packit c4476c
2. To generate a RSA key
Packit c4476c
Packit c4476c
A RSA key can be used both for encryption and for signing.
Packit c4476c
Packit c4476c
Generating a key for the RSA algorithm is quite easy, all you have to
Packit c4476c
do is the following:
Packit c4476c
Packit c4476c
  openssl genrsa -des3 -out privkey.pem 2048
Packit c4476c
Packit c4476c
With this variant, you will be prompted for a protecting password.  If
Packit c4476c
you don't want your key to be protected by a password, remove the flag
Packit c4476c
'-des3' from the command line above.
Packit c4476c
Packit c4476c
The number 2048 is the size of the key, in bits.  Today, 2048 or
Packit c4476c
higher is recommended for RSA keys, as fewer amount of bits is
Packit c4476c
consider insecure or to be insecure pretty soon.
Packit c4476c
Packit c4476c
Packit c4476c
3. To generate a DSA key
Packit c4476c
Packit c4476c
A DSA key can be used for signing only.  It is important to
Packit c4476c
know what a certificate request with a DSA key can really be used for.
Packit c4476c
Packit c4476c
Generating a key for the DSA algorithm is a two-step process.  First,
Packit c4476c
you have to generate parameters from which to generate the key:
Packit c4476c
Packit c4476c
  openssl dsaparam -out dsaparam.pem 2048
Packit c4476c
Packit c4476c
The number 2048 is the size of the key, in bits.  Today, 2048 or
Packit c4476c
higher is recommended for DSA keys, as fewer amount of bits is
Packit c4476c
consider insecure or to be insecure pretty soon.
Packit c4476c
Packit c4476c
When that is done, you can generate a key using the parameters in
Packit c4476c
question (actually, several keys can be generated from the same
Packit c4476c
parameters):
Packit c4476c
Packit c4476c
  openssl gendsa -des3 -out privkey.pem dsaparam.pem
Packit c4476c
Packit c4476c
With this variant, you will be prompted for a protecting password.  If
Packit c4476c
you don't want your key to be protected by a password, remove the flag
Packit c4476c
'-des3' from the command line above.
Packit c4476c
Packit c4476c
Packit c4476c
4. To generate an EC key
Packit c4476c
Packit c4476c
An EC key can be used both for key agreement (ECDH) and signing (ECDSA).
Packit c4476c
Packit c4476c
Generating a key for ECC is similar to generating a DSA key. These are
Packit c4476c
two-step processes. First, you have to get the EC parameters from which
Packit c4476c
the key will be generated:
Packit c4476c
Packit c4476c
  openssl ecparam -name prime256v1 -out prime256v1.pem
Packit c4476c
Packit c4476c
The prime256v1, or NIST P-256, which stands for 'X9.62/SECG curve over
Packit c4476c
a 256-bit prime field', is the name of an elliptic curve which generates the
Packit c4476c
parameters. You can use the following command to list all supported curves:
Packit c4476c
Packit c4476c
  openssl ecparam -list_curves
Packit c4476c
Packit c4476c
When that is done, you can generate a key using the created parameters (several
Packit c4476c
keys can be produced from the same parameters):
Packit c4476c
Packit c4476c
  openssl genpkey -des3 -paramfile prime256v1.pem -out private.key
Packit c4476c
Packit c4476c
With this variant, you will be prompted for a password to protect your key.
Packit c4476c
If you don't want your key to be protected by a password, remove the flag
Packit c4476c
'-des3' from the command line above.
Packit c4476c
Packit c4476c
You can also directly generate the key in one step:
Packit c4476c
Packit c4476c
  openssl ecparam -genkey -name prime256v1 -out private.key
Packit c4476c
Packit c4476c
or
Packit c4476c
Packit c4476c
  openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256
Packit c4476c
Packit c4476c
Packit c4476c
5. NOTE
Packit c4476c
Packit c4476c
If you intend to use the key together with a server certificate,
Packit c4476c
it may be reasonable to avoid protecting it with a password, since
Packit c4476c
otherwise someone would have to type in the password every time the
Packit c4476c
server needs to access the key.
Packit c4476c
Packit c4476c
For X25519 and X448, it's treated as a distinct algorithm but not as one of
Packit c4476c
the curves listed with 'ecparam -list_curves' option. You can use
Packit c4476c
the following command to generate an X25519 key:
Packit c4476c
Packit c4476c
  openssl genpkey -algorithm X25519 -out xkey.pem