2
0

keys.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <DRAFT!>
  2. HOWTO keys
  3. 1. Introduction
  4. Keys are the basis of public key algorithms and PKI. Keys usually
  5. come in pairs, with one half being the public key and the other half
  6. being the private key. With OpenSSL, the private key contains the
  7. public key information as well, so a public key doesn't need to be
  8. generated separately.
  9. Public keys come in several flavors, using different cryptographic
  10. algorithms. The most popular ones associated with certificates are
  11. RSA and DSA, and this HOWTO will show how to generate each of them.
  12. 2. To generate a RSA key
  13. A RSA key can be used both for encryption and for signing.
  14. Generating a key for the RSA algorithm is quite easy, all you have to
  15. do is the following:
  16. openssl genrsa -des3 -out privkey.pem 2048
  17. With this variant, you will be prompted for a protecting password. If
  18. you don't want your key to be protected by a password, remove the flag
  19. '-des3' from the command line above.
  20. The number 2048 is the size of the key, in bits. Today, 2048 or
  21. higher is recommended for RSA keys, as fewer amount of bits is
  22. consider insecure or to be insecure pretty soon.
  23. 3. To generate a DSA key
  24. A DSA key can be used for signing only. It is important to
  25. know what a certificate request with a DSA key can really be used for.
  26. Generating a key for the DSA algorithm is a two-step process. First,
  27. you have to generate parameters from which to generate the key:
  28. openssl dsaparam -out dsaparam.pem 2048
  29. The number 2048 is the size of the key, in bits. Today, 2048 or
  30. higher is recommended for DSA keys, as fewer amount of bits is
  31. consider insecure or to be insecure pretty soon.
  32. When that is done, you can generate a key using the parameters in
  33. question (actually, several keys can be generated from the same
  34. parameters):
  35. openssl gendsa -des3 -out privkey.pem dsaparam.pem
  36. With this variant, you will be prompted for a protecting password. If
  37. you don't want your key to be protected by a password, remove the flag
  38. '-des3' from the command line above.
  39. 4. To generate an EC key
  40. An EC key can be used both for key agreement (ECDH) and signing (ECDSA).
  41. Generating a key for ECC is similar to generating a DSA key. These are
  42. two-step processes. First, you have to get the EC parameters from which
  43. the key will be generated:
  44. openssl ecparam -name prime256v1 -out prime256v1.pem
  45. The prime256v1, or NIST P-256, which stands for 'X9.62/SECG curve over
  46. a 256-bit prime field', is the name of an elliptic curve which generates the
  47. parameters. You can use the following command to list all supported curves:
  48. openssl ecparam -list_curves
  49. When that is done, you can generate a key using the created parameters (several
  50. keys can be produced from the same parameters):
  51. openssl genpkey -des3 -paramfile prime256v1.pem -out private.key
  52. With this variant, you will be prompted for a password to protect your key.
  53. If you don't want your key to be protected by a password, remove the flag
  54. '-des3' from the command line above.
  55. You can also directly generate the key in one step:
  56. openssl ecparam -genkey -name prime256v1 -out private.key
  57. or
  58. openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256
  59. 5. NOTE
  60. If you intend to use the key together with a server certificate,
  61. it may be reasonable to avoid protecting it with a password, since
  62. otherwise someone would have to type in the password every time the
  63. server needs to access the key.
  64. For X25519 and X448, it's treated as a distinct algorithm but not as one of
  65. the curves listed with 'ecparam -list_curves' option. You can use
  66. the following command to generate an X25519 key:
  67. openssl genpkey -algorithm X25519 -out xkey.pem