man-pages/man1/genpkey.1ssl.html
2021-03-31 01:06:50 +01:00

538 lines
14 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GENPKEY</TITLE>
</HEAD><BODY>
<H1>GENPKEY</H1>
Section: OpenSSL (1SSL)<BR>Updated: 2021-03-22<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
openssl-genpkey, genpkey - generate a private key
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>openssl</B> <B>genpkey</B>
[<B>-help</B>]
[<B>-out filename</B>]
[<B>-outform PEM|DER</B>]
[<B>-pass arg</B>]
[<B>-</B>cipher<B></B>]
[<B>-engine id</B>]
[<B>-paramfile file</B>]
[<B>-algorithm alg</B>]
[<B>-pkeyopt opt:value</B>]
[<B>-genparam</B>]
[<B>-text</B>]
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The <B>genpkey</B> command generates a private key.
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="1"><B>-help</B><DD>
Print out a usage message.
<DT id="2"><B>-out filename</B><DD>
Output the key to the specified file. If this argument is not specified then
standard output is used.
<DT id="3"><B>-outform DER|PEM</B><DD>
This specifies the output format <FONT SIZE="-1">DER</FONT> or <FONT SIZE="-1">PEM.</FONT> The default format is <FONT SIZE="-1">PEM.</FONT>
<DT id="4"><B>-pass arg</B><DD>
The output file password source. For more information about the format of <B>arg</B>
see the <B></B><FONT SIZE="-1"><B>PASS PHRASE ARGUMENTS</B></FONT><B></B> section in <B><A HREF="/cgi-bin/man/man2html?1+openssl">openssl</A></B>(1).
<DT id="5"><B>-</B>cipher<B></B><DD>
This option encrypts the private key with the supplied cipher. Any algorithm
name accepted by <B>EVP_get_cipherbyname()</B> is acceptable such as <B>des3</B>.
<DT id="6"><B>-engine id</B><DD>
Specifying an engine (by its unique <B>id</B> string) will cause <B>genpkey</B>
to attempt to obtain a functional reference to the specified engine,
thus initialising it if needed. The engine will then be set as the default
for all available algorithms. If used this option should precede all other
options.
<DT id="7"><B>-algorithm alg</B><DD>
Public key algorithm to use such as <FONT SIZE="-1">RSA, DSA</FONT> or <FONT SIZE="-1">DH.</FONT> If used this option must
precede any <B>-pkeyopt</B> options. The options <B>-paramfile</B> and <B>-algorithm</B>
are mutually exclusive. Engines may add algorithms in addition to the standard
built-in ones.
<P>
Valid built-in algorithm names for private key generation are <FONT SIZE="-1">RSA,</FONT> RSA-PSS, <FONT SIZE="-1">EC,
X25519, X448, ED25519</FONT> and <FONT SIZE="-1">ED448.</FONT>
<P>
Valid built-in algorithm names for parameter generation (see the <B>-genparam</B>
option) are <FONT SIZE="-1">DH, DSA</FONT> and <FONT SIZE="-1">EC.</FONT>
<P>
Note that the algorithm name X9.42 <FONT SIZE="-1">DH</FONT> may be used as a synonym for the <FONT SIZE="-1">DH</FONT>
algorithm. These are identical and do not indicate the type of parameters that
will be generated. Use the <B>dh_paramgen_type</B> option to indicate whether PKCS#3
or X9.42 <FONT SIZE="-1">DH</FONT> parameters are required. See ``<FONT SIZE="-1">DH</FONT> Parameter Generation Options''
below for more details.
<DT id="8"><B>-pkeyopt opt:value</B><DD>
Set the public key algorithm option <B>opt</B> to <B>value</B>. The precise set of
options supported depends on the public key algorithm used and its
implementation. See ``<FONT SIZE="-1">KEY GENERATION OPTIONS''</FONT> and
``<FONT SIZE="-1">PARAMETER GENERATION OPTIONS''</FONT> below for more details.
<DT id="9"><B>-genparam</B><DD>
Generate a set of parameters instead of a private key. If used this option must
precede any <B>-algorithm</B>, <B>-paramfile</B> or <B>-pkeyopt</B> options.
<DT id="10"><B>-paramfile filename</B><DD>
Some public key algorithms generate a private key based on a set of parameters.
They can be supplied using this option. If this option is used the public key
algorithm used is determined by the parameters. If used this option must
precede any <B>-pkeyopt</B> options. The options <B>-paramfile</B> and <B>-algorithm</B>
are mutually exclusive.
<DT id="11"><B>-text</B><DD>
Print an (unencrypted) text representation of private and public keys and
parameters along with the <FONT SIZE="-1">PEM</FONT> or <FONT SIZE="-1">DER</FONT> structure.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>KEY GENERATION OPTIONS</H2>
The options supported by each algorithm and indeed each implementation of an
algorithm can vary. The options for the OpenSSL implementations are detailed
below. There are no key generation options defined for the X25519, X448, <FONT SIZE="-1">ED25519</FONT>
or <FONT SIZE="-1">ED448</FONT> algorithms.
<A NAME="lbAG">&nbsp;</A>
<H3><FONT SIZE="-1">RSA</FONT> Key Generation Options</H3>
<DL COMPACT>
<DT id="12"><B>rsa_keygen_bits:numbits</B><DD>
The number of bits in the generated key. If not specified 2048 is used.
<DT id="13"><B>rsa_keygen_primes:numprimes</B><DD>
The number of primes in the generated key. If not specified 2 is used.
<DT id="14"><B>rsa_keygen_pubexp:value</B><DD>
The <FONT SIZE="-1">RSA</FONT> public exponent value. This can be a large decimal or
hexadecimal value if preceded by <B>0x</B>. Default value is 65537.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H3>RSA-PSS Key Generation Options</H3>
Note: by default an <B>RSA-PSS</B> key has no parameter restrictions.
<DL COMPACT>
<DT id="15"><B>rsa_keygen_bits:numbits</B>, <B>rsa_keygen_primes:numprimes</B>, <B>rsa_keygen_pubexp:value</B><DD>
These options have the same meaning as the <B></B><FONT SIZE="-1"><B>RSA</B></FONT><B></B> algorithm.
<DT id="16"><B>rsa_pss_keygen_md:digest</B><DD>
If set the key is restricted and can only use <B>digest</B> for signing.
<DT id="17"><B>rsa_pss_keygen_mgf1_md:digest</B><DD>
If set the key is restricted and can only use <B>digest</B> as it's <FONT SIZE="-1">MGF1</FONT>
parameter.
<DT id="18"><B>rsa_pss_keygen_saltlen:len</B><DD>
If set the key is restricted and <B>len</B> specifies the minimum salt length.
</DL>
<A NAME="lbAI">&nbsp;</A>
<H3><FONT SIZE="-1">EC</FONT> Key Generation Options</H3>
The <FONT SIZE="-1">EC</FONT> key generation options can also be used for parameter generation.
<DL COMPACT>
<DT id="19"><B>ec_paramgen_curve:curve</B><DD>
The <FONT SIZE="-1">EC</FONT> curve to use. OpenSSL supports <FONT SIZE="-1">NIST</FONT> curve names such as ``P-256''.
<DT id="20"><B>ec_param_enc:encoding</B><DD>
The encoding to use for parameters. The ``encoding'' parameter must be either
``named_curve'' or ``explicit''. The default value is ``named_curve''.
</DL>
<A NAME="lbAJ">&nbsp;</A>
<H2>PARAMETER GENERATION OPTIONS</H2>
The options supported by each algorithm and indeed each implementation of an
algorithm can vary. The options for the OpenSSL implementations are detailed
below.
<A NAME="lbAK">&nbsp;</A>
<H3><FONT SIZE="-1">DSA</FONT> Parameter Generation Options</H3>
<DL COMPACT>
<DT id="21"><B>dsa_paramgen_bits:numbits</B><DD>
The number of bits in the generated prime. If not specified 2048 is used.
<DT id="22"><B>dsa_paramgen_q_bits:numbits</B><DD>
The number of bits in the q parameter. Must be one of 160, 224 or 256. If not
specified 224 is used.
<DT id="23"><B>dsa_paramgen_md:digest</B><DD>
The digest to use during parameter generation. Must be one of <B>sha1</B>, <B>sha224</B>
or <B>sha256</B>. If set, then the number of bits in <B>q</B> will match the output size
of the specified digest and the <B>dsa_paramgen_q_bits</B> parameter will be
ignored. If not set, then a digest will be used that gives an output matching
the number of bits in <B>q</B>, i.e. <B>sha1</B> if q length is 160, <B>sha224</B> if it 224
or <B>sha256</B> if it is 256.
</DL>
<A NAME="lbAL">&nbsp;</A>
<H3><FONT SIZE="-1">DH</FONT> Parameter Generation Options</H3>
<DL COMPACT>
<DT id="24"><B>dh_paramgen_prime_len:numbits</B><DD>
The number of bits in the prime parameter <B>p</B>. The default is 2048.
<DT id="25"><B>dh_paramgen_subprime_len:numbits</B><DD>
The number of bits in the sub prime parameter <B>q</B>. The default is 256 if the
prime is at least 2048 bits long or 160 otherwise. Only relevant if used in
conjunction with the <B>dh_paramgen_type</B> option to generate X9.42 <FONT SIZE="-1">DH</FONT> parameters.
<DT id="26"><B>dh_paramgen_generator:value</B><DD>
The value to use for the generator <B>g</B>. The default is 2.
<DT id="27"><B>dh_paramgen_type:value</B><DD>
The type of <FONT SIZE="-1">DH</FONT> parameters to generate. Use 0 for PKCS#3 <FONT SIZE="-1">DH</FONT> and 1 for X9.42 <FONT SIZE="-1">DH.</FONT>
The default is 0.
<DT id="28"><B>dh_rfc5114:num</B><DD>
If this option is set, then the appropriate <FONT SIZE="-1">RFC5114</FONT> parameters are used
instead of generating new parameters. The value <B>num</B> can take the
values 1, 2 or 3 corresponding to <FONT SIZE="-1">RFC5114 DH</FONT> parameters consisting of
1024 bit group with 160 bit subgroup, 2048 bit group with 224 bit subgroup
and 2048 bit group with 256 bit subgroup as mentioned in <FONT SIZE="-1">RFC5114</FONT> sections
2.1, 2.2 and 2.3 respectively. If present this overrides all other <FONT SIZE="-1">DH</FONT> parameter
options.
</DL>
<A NAME="lbAM">&nbsp;</A>
<H3><FONT SIZE="-1">EC</FONT> Parameter Generation Options</H3>
The <FONT SIZE="-1">EC</FONT> parameter generation options are the same as for key generation. See
``<FONT SIZE="-1">EC</FONT> Key Generation Options'' above.
<A NAME="lbAN">&nbsp;</A>
<H2>NOTES</H2>
The use of the genpkey program is encouraged over the algorithm specific
utilities because additional algorithm options and <FONT SIZE="-1">ENGINE</FONT> provided algorithms
can be used.
<A NAME="lbAO">&nbsp;</A>
<H2>EXAMPLES</H2>
Generate an <FONT SIZE="-1">RSA</FONT> private key using default parameters:
<P>
<PRE>
openssl genpkey -algorithm RSA -out key.pem
</PRE>
<P>
Encrypt output private key using 128 bit <FONT SIZE="-1">AES</FONT> and the passphrase ``hello'':
<P>
<PRE>
openssl genpkey -algorithm RSA -out key.pem -aes-128-cbc -pass pass:hello
</PRE>
<P>
Generate a 2048 bit <FONT SIZE="-1">RSA</FONT> key using 3 as the public exponent:
<P>
<PRE>
openssl genpkey -algorithm RSA -out key.pem \
-pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:3
</PRE>
<P>
Generate 2048 bit <FONT SIZE="-1">DSA</FONT> parameters:
<P>
<PRE>
openssl genpkey -genparam -algorithm DSA -out dsap.pem \
-pkeyopt dsa_paramgen_bits:2048
</PRE>
<P>
Generate <FONT SIZE="-1">DSA</FONT> key from parameters:
<P>
<PRE>
openssl genpkey -paramfile dsap.pem -out dsakey.pem
</PRE>
<P>
Generate 2048 bit <FONT SIZE="-1">DH</FONT> parameters:
<P>
<PRE>
openssl genpkey -genparam -algorithm DH -out dhp.pem \
-pkeyopt dh_paramgen_prime_len:2048
</PRE>
<P>
Generate 2048 bit X9.42 <FONT SIZE="-1">DH</FONT> parameters:
<P>
<PRE>
openssl genpkey -genparam -algorithm DH -out dhpx.pem \
-pkeyopt dh_paramgen_prime_len:2048 \
-pkeyopt dh_paramgen_type:1
</PRE>
<P>
Output <FONT SIZE="-1">RFC5114 2048</FONT> bit <FONT SIZE="-1">DH</FONT> parameters with 224 bit subgroup:
<P>
<PRE>
openssl genpkey -genparam -algorithm DH -out dhp.pem -pkeyopt dh_rfc5114:2
</PRE>
<P>
Generate <FONT SIZE="-1">DH</FONT> key from parameters:
<P>
<PRE>
openssl genpkey -paramfile dhp.pem -out dhkey.pem
</PRE>
<P>
Generate <FONT SIZE="-1">EC</FONT> parameters:
<P>
<PRE>
openssl genpkey -genparam -algorithm EC -out ecp.pem \
-pkeyopt ec_paramgen_curve:secp384r1 \
-pkeyopt ec_param_enc:named_curve
</PRE>
<P>
Generate <FONT SIZE="-1">EC</FONT> key from parameters:
<P>
<PRE>
openssl genpkey -paramfile ecp.pem -out eckey.pem
</PRE>
<P>
Generate <FONT SIZE="-1">EC</FONT> key directly:
<P>
<PRE>
openssl genpkey -algorithm EC -out eckey.pem \
-pkeyopt ec_paramgen_curve:P-384 \
-pkeyopt ec_param_enc:named_curve
</PRE>
<P>
Generate an X25519 private key:
<P>
<PRE>
openssl genpkey -algorithm X25519 -out xkey.pem
</PRE>
<P>
Generate an <FONT SIZE="-1">ED448</FONT> private key:
<P>
<PRE>
openssl genpkey -algorithm ED448 -out xkey.pem
</PRE>
<A NAME="lbAP">&nbsp;</A>
<H2>HISTORY</H2>
The ability to use <FONT SIZE="-1">NIST</FONT> curve names, and to generate an <FONT SIZE="-1">EC</FONT> key directly,
were added in OpenSSL 1.0.2.
The ability to generate X25519 keys was added in OpenSSL 1.1.0.
The ability to generate X448, <FONT SIZE="-1">ED25519</FONT> and <FONT SIZE="-1">ED448</FONT> keys was added in OpenSSL 1.1.1.
<A NAME="lbAQ">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
<P>
Licensed under the OpenSSL license (the ``License''). You may not use
this file except in compliance with the License. You can obtain a copy
in the file <FONT SIZE="-1">LICENSE</FONT> in the source distribution or at
&lt;<A HREF="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</A>&gt;.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="29"><A HREF="#lbAB">NAME</A><DD>
<DT id="30"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="31"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="32"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="33"><A HREF="#lbAF">KEY GENERATION OPTIONS</A><DD>
<DL>
<DT id="34"><A HREF="#lbAG"><FONT SIZE="-1">RSA</FONT> Key Generation Options</A><DD>
<DT id="35"><A HREF="#lbAH">RSA-PSS Key Generation Options</A><DD>
<DT id="36"><A HREF="#lbAI"><FONT SIZE="-1">EC</FONT> Key Generation Options</A><DD>
</DL>
<DT id="37"><A HREF="#lbAJ">PARAMETER GENERATION OPTIONS</A><DD>
<DL>
<DT id="38"><A HREF="#lbAK"><FONT SIZE="-1">DSA</FONT> Parameter Generation Options</A><DD>
<DT id="39"><A HREF="#lbAL"><FONT SIZE="-1">DH</FONT> Parameter Generation Options</A><DD>
<DT id="40"><A HREF="#lbAM"><FONT SIZE="-1">EC</FONT> Parameter Generation Options</A><DD>
</DL>
<DT id="41"><A HREF="#lbAN">NOTES</A><DD>
<DT id="42"><A HREF="#lbAO">EXAMPLES</A><DD>
<DT id="43"><A HREF="#lbAP">HISTORY</A><DD>
<DT id="44"><A HREF="#lbAQ">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:13 GMT, March 31, 2021
</BODY>
</HTML>