6 pkeyutl - public key algorithm utility
16 [B<-keyform PEM|DER|ENGINE>]
19 [B<-peerform PEM|DER|ENGINE>]
31 [B<-pkeyopt opt:value>]
41 The B<pkeyutl> command can be used to perform public key operations using
42 any supported algorithm.
50 Print out a usage message.
54 This specifies the input filename to read data from or standard input
55 if this option is not specified.
57 =item B<-out filename>
59 Specifies the output filename to write to or standard output by
62 =item B<-sigfile file>
64 Signature file, required for B<verify> operations only
68 The input key file, by default it should be a private key.
70 =item B<-keyform PEM|DER|ENGINE>
72 The key format PEM, DER or ENGINE. Default is PEM.
76 The input key password source. For more information about the format of B<arg>
77 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
79 =item B<-peerkey file>
81 The peer key file, used by key derivation (agreement) operations.
83 =item B<-peerform PEM|DER|ENGINE>
85 The peer key format PEM, DER or ENGINE. Default is PEM.
89 The input file is a public key.
93 The input is a certificate containing a public key.
97 Reverse the order of the input buffer. This is useful for some libraries
98 (such as CryptoAPI) which represent the buffer in little endian format.
102 Sign the input data and output the signed result. This requires
107 Verify the input data against the signature file and indicate if the
108 verification succeeded or failed.
110 =item B<-verifyrecover>
112 Verify the input data and output the recovered data.
116 Encrypt the input data using a public key.
120 Decrypt the input data using a private key.
124 Derive a shared secret using the peer key.
126 =item B<-kdf algorithm>
128 Use key derivation function B<algorithm>. The supported algorithms are
129 at present B<TLS1-PRF> and B<HKDF>.
130 Note: additional parameters and the KDF output length will normally have to be
131 set for this to work.
132 See L<EVP_PKEY_CTX_set_hkdf_md(3)> and L<EVP_PKEY_CTX_set_tls1_prf_md(3)>
133 for the supported string parameters of each algorithm.
135 =item B<-kdflen length>
137 Set the output length for KDF.
139 =item B<-pkeyopt opt:value>
141 Public key options specified as opt:value. See NOTES below for more details.
145 hex dump the output data.
149 Parse the ASN.1 output data, this is useful when combined with the
150 B<-verifyrecover> option when an ASN1 structure is signed.
152 =item B<-rand file...>
154 A file or files containing random data used to seed the random number
156 Multiple files can be specified separated by an OS-dependent character.
157 The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
160 =item [B<-writerand file>]
162 Writes random data to the specified I<file> upon exit.
163 This can be used with a subsequent B<-rand> flag.
167 Specifying an engine (by its unique B<id> string) will cause B<pkeyutl>
168 to attempt to obtain a functional reference to the specified engine,
169 thus initialising it if needed. The engine will then be set as the default
170 for all available algorithms.
172 =item B<-engine_impl>
174 When used with the B<-engine> option, it specifies to also use
175 engine B<id> for crypto operations.
181 The operations and options supported vary according to the key algorithm
182 and its implementation. The OpenSSL operations and options are indicated below.
184 Unless otherwise mentioned all algorithms support the B<digest:alg> option
185 which specifies the digest in use for sign, verify and verifyrecover operations.
186 The value B<alg> should represent a digest name as used in the
187 EVP_get_digestbyname() function for example B<sha1>.
188 This value is used only for sanity-checking the lengths of data passed in to
189 the B<pkeyutl> and for creating the structures that make up the signature
190 (e.g. B<DigestInfo> in RSASSA PKCS#1 v1.5 signatures).
191 In case of RSA, ECDSA and DSA signatures, this utility
192 will not perform hashing on input data but rather use the data directly as
193 input of signature algorithm. Depending on key type, signature type and mode
194 of padding, the maximum acceptable lengths of input data differ. In general,
195 with RSA the signed data can't be longer than the key modulus, in case of ECDSA
196 and DSA the data shouldn't be longer than field size, otherwise it will be
197 silently truncated to field size.
199 In other words, if the value of digest is B<sha1> the input should be 20 bytes
200 long binary encoding of SHA-1 hash function output.
204 The RSA algorithm generally supports the encrypt, decrypt, sign,
205 verify and verifyrecover operations. However, some padding modes
206 support only a subset of these operations. The following additional
207 B<pkeyopt> values are supported:
211 =item B<rsa_padding_mode:mode>
213 This sets the RSA padding mode. Acceptable values for B<mode> are B<pkcs1> for
214 PKCS#1 padding, B<sslv23> for SSLv23 padding, B<none> for no padding, B<oaep>
215 for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS.
217 In PKCS#1 padding if the message digest is not set then the supplied data is
218 signed or verified directly instead of using a B<DigestInfo> structure. If a
219 digest is set then the a B<DigestInfo> structure is used and its the length
220 must correspond to the digest type.
222 For B<oaep> mode only encryption and decryption is supported.
224 For B<x931> if the digest type is set it is used to format the block data
225 otherwise the first byte is used to specify the X9.31 digest ID. Sign,
226 verify and verifyrecover are can be performed in this mode.
228 For B<pss> mode only sign and verify are supported and the digest type must be
231 =item B<rsa_pss_saltlen:len>
233 For B<pss> mode only this option specifies the salt length. Three special
234 values are supported: "digest" sets the salt length to the digest length,
235 "max" sets the salt length to the maximum permissible value. When verifying
236 "auto" causes the salt length to be automatically determined based on the
237 B<PSS> block structure.
239 =item B<rsa_mgf1_md:digest>
241 For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest is not
242 explicitly set in PSS mode then the signing digest is used.
246 =head1 RSA-PSS ALGORITHM
248 The RSA-PSS algorithm is a restricted version of the RSA algorithm which only
249 supports the sign and verify operations with PSS padding. The following
250 additional B<pkeyopt> values are supported:
254 =item B<rsa_padding_mode:mode>, B<rsa_pss_saltlen:len>, B<rsa_mgf1_md:digest>
256 These have the same meaning as the B<RSA> algorithm with some additional
257 restrictions. The padding mode can only be set to B<pss> which is the
260 If the key has parameter restrictions than the digest, MGF1
261 digest and salt length are set to the values specified in the parameters.
262 The digest and MG cannot be changed and the salt length cannot be set to a
263 value less than the minimum restriction.
269 The DSA algorithm supports signing and verification operations only. Currently
270 there are no additional options other than B<digest>. Only the SHA1
271 digest can be used and this digest is assumed by default.
275 The DH algorithm only supports the derivation operation and no additional
280 The EC algorithm supports sign, verify and derive operations. The sign and
281 verify operations use ECDSA and derive uses ECDH. Currently there are no
282 additional options other than B<digest>. Only the SHA1 digest can be used and
283 this digest is assumed by default.
285 =head1 X25519 and X448 ALGORITHMS
287 The X25519 and X448 algorithms support key derivation only. Currently there are
288 no additional options.
292 Sign some data using a private key:
294 openssl pkeyutl -sign -in file -inkey key.pem -out sig
296 Recover the signed data (e.g. if an RSA key is used):
298 openssl pkeyutl -verifyrecover -in sig -inkey key.pem
300 Verify the signature (e.g. a DSA key):
302 openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
304 Sign data using a message digest value (this is currently only valid for RSA):
306 openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
308 Derive a shared secret value:
310 openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
312 Hexdump 48 bytes of TLS1 PRF using digest B<SHA256> and shared secret and
313 seed consisting of the single byte 0xFF:
315 openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \
316 -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump
320 L<genpkey(1)>, L<pkey(1)>, L<rsautl(1)>
321 L<dgst(1)>, L<rsa(1)>, L<genrsa(1)>,
322 L<EVP_PKEY_CTX_set_hkdf_md(3)>, L<EVP_PKEY_CTX_set_tls1_prf_md(3)>
326 Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
328 Licensed under the OpenSSL license (the "License"). You may not use
329 this file except in compliance with the License. You can obtain a copy
330 in the file LICENSE in the source distribution or at
331 L<https://www.openssl.org/source/license.html>.