1OPENSSL-PKEYUTL(1ossl)              OpenSSL             OPENSSL-PKEYUTL(1ossl)
2
3
4

NAME

6       openssl-pkeyutl - public key algorithm command
7

SYNOPSIS

9       openssl pkeyutl [-help] [-in file] [-rawin] [-digest algorithm] [-out
10       file] [-sigfile file] [-inkey filename|uri] [-keyform
11       DER|PEM|P12|ENGINE] [-passin arg] [-peerkey file] [-peerform
12       DER|PEM|P12|ENGINE] [-pubin] [-certin] [-rev] [-sign] [-verify]
13       [-verifyrecover] [-encrypt] [-decrypt] [-derive] [-kdf algorithm]
14       [-kdflen length] [-pkeyopt opt:value] [-pkeyopt_passin opt[:passarg]]
15       [-hexdump] [-asn1parse] [-engine id] [-engine_impl] [-rand files]
16       [-writerand file] [-provider name] [-provider-path path] [-propquery
17       propq] [-config configfile]
18

DESCRIPTION

20       This command can be used to perform low-level public key operations
21       using any supported algorithm.
22

OPTIONS

24       -help
25           Print out a usage message.
26
27       -in filename
28           This specifies the input filename to read data from or standard
29           input if this option is not specified.
30
31       -rawin
32           This indicates that the input data is raw data, which is not hashed
33           by any message digest algorithm. The user can specify a digest
34           algorithm by using the -digest option. This option can only be used
35           with -sign and -verify and must be used with the Ed25519 and Ed448
36           algorithms.
37
38       -digest algorithm
39           This specifies the digest algorithm which is used to hash the input
40           data before signing or verifying it with the input key. This option
41           could be omitted if the signature algorithm does not require one
42           (for instance, EdDSA). If this option is omitted but the signature
43           algorithm requires one, a default value will be used. For signature
44           algorithms like RSA, DSA and ECDSA, SHA-256 will be the default
45           digest algorithm. For SM2, it will be SM3. If this option is
46           present, then the -rawin option must be also specified.
47
48       -out filename
49           Specifies the output filename to write to or standard output by
50           default.
51
52       -sigfile file
53           Signature file, required for -verify operations only
54
55       -inkey filename|uri
56           The input key, by default it should be a private key.
57
58       -keyform DER|PEM|P12|ENGINE
59           The key format; unspecified by default.  See
60           openssl-format-options(1) for details.
61
62       -passin arg
63           The input key password source. For more information about the
64           format of arg see openssl-passphrase-options(1).
65
66       -peerkey file
67           The peer key file, used by key derivation (agreement) operations.
68
69       -peerform DER|PEM|P12|ENGINE
70           The peer key format; unspecified by default.  See
71           openssl-format-options(1) for details.
72
73       -pubin
74           The input file is a public key.
75
76       -certin
77           The input is a certificate containing a public key.
78
79       -rev
80           Reverse the order of the input buffer. This is useful for some
81           libraries (such as CryptoAPI) which represent the buffer in little
82           endian format.
83
84       -sign
85           Sign the input data (which must be a hash) and output the signed
86           result. This requires a private key.
87
88       -verify
89           Verify the input data (which must be a hash) against the signature
90           file and indicate if the verification succeeded or failed.
91
92       -verifyrecover
93           Verify the input data (which must be a hash) and output the
94           recovered data.
95
96       -encrypt
97           Encrypt the input data using a public key.
98
99       -decrypt
100           Decrypt the input data using a private key.
101
102       -derive
103           Derive a shared secret using the peer key.
104
105       -kdf algorithm
106           Use key derivation function algorithm.  The supported algorithms
107           are at present TLS1-PRF and HKDF.  Note: additional parameters and
108           the KDF output length will normally have to be set for this to
109           work.  See EVP_PKEY_CTX_set_hkdf_md(3) and
110           EVP_PKEY_CTX_set_tls1_prf_md(3) for the supported string parameters
111           of each algorithm.
112
113       -kdflen length
114           Set the output length for KDF.
115
116       -pkeyopt opt:value
117           Public key options specified as opt:value. See NOTES below for more
118           details.
119
120       -pkeyopt_passin opt[:passarg]
121           Allows reading a public key option opt from stdin or a password
122           source.  If only opt is specified, the user will be prompted to
123           enter a password on stdin.  Alternatively, passarg can be specified
124           which can be any value supported by openssl-passphrase-options(1).
125
126       -hexdump
127           hex dump the output data.
128
129       -asn1parse
130           Parse the ASN.1 output data, this is useful when combined with the
131           -verifyrecover option when an ASN1 structure is signed.
132
133       -engine id
134           See "Engine Options" in openssl(1).  This option is deprecated.
135
136       -engine_impl
137           When used with the -engine option, it specifies to also use engine
138           id for crypto operations.
139
140       -rand files, -writerand file
141           See "Random State Options" in openssl(1) for details.
142
143       -provider name
144       -provider-path path
145       -propquery propq
146           See "Provider Options" in openssl(1), provider(7), and property(7).
147
148       -config configfile
149           See "Configuration Option" in openssl(1).
150

NOTES

152       The operations and options supported vary according to the key
153       algorithm and its implementation. The OpenSSL operations and options
154       are indicated below.
155
156       Unless otherwise mentioned all algorithms support the digest:alg option
157       which specifies the digest in use for sign, verify and verifyrecover
158       operations.  The value alg should represent a digest name as used in
159       the EVP_get_digestbyname() function for example sha1. This value is not
160       used to hash the input data. It is used (by some algorithms) for
161       sanity-checking the lengths of data passed in and for creating the
162       structures that make up the signature (e.g. DigestInfo in RSASSA PKCS#1
163       v1.5 signatures).
164
165       This command does not hash the input data (except where -rawin is used)
166       but rather it will use the data directly as input to the signature
167       algorithm.  Depending on the key type, signature type, and mode of
168       padding, the maximum acceptable lengths of input data differ. The
169       signed data can't be longer than the key modulus with RSA. In case of
170       ECDSA and DSA the data shouldn't be longer than the field size,
171       otherwise it will be silently truncated to the field size.  In any
172       event the input size must not be larger than the largest supported
173       digest size.
174
175       In other words, if the value of digest is sha1 the input should be the
176       20 bytes long binary encoding of the SHA-1 hash function output.
177

RSA ALGORITHM

179       The RSA algorithm generally supports the encrypt, decrypt, sign, verify
180       and verifyrecover operations. However, some padding modes support only
181       a subset of these operations. The following additional pkeyopt values
182       are supported:
183
184       rsa_padding_mode:mode
185           This sets the RSA padding mode. Acceptable values for mode are
186           pkcs1 for PKCS#1 padding, none for no padding, oaep for OAEP mode,
187           x931 for X9.31 mode and pss for PSS.
188
189           In PKCS#1 padding if the message digest is not set then the
190           supplied data is signed or verified directly instead of using a
191           DigestInfo structure. If a digest is set then the a DigestInfo
192           structure is used and its the length must correspond to the digest
193           type.
194
195           Note, for pkcs1 padding, as a protection against Bleichenbacher
196           attack, the decryption will not fail in case of padding check
197           failures. Use none and manual inspection of the decrypted message
198           to verify if the decrypted value has correct PKCS#1 v1.5 padding.
199
200           For oaep mode only encryption and decryption is supported.
201
202           For x931 if the digest type is set it is used to format the block
203           data otherwise the first byte is used to specify the X9.31 digest
204           ID. Sign, verify and verifyrecover are can be performed in this
205           mode.
206
207           For pss mode only sign and verify are supported and the digest type
208           must be specified.
209
210       rsa_pss_saltlen:len
211           For pss mode only this option specifies the salt length. Three
212           special values are supported: digest sets the salt length to the
213           digest length, max sets the salt length to the maximum permissible
214           value. When verifying auto causes the salt length to be
215           automatically determined based on the PSS block structure.
216
217       rsa_mgf1_md:digest
218           For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest
219           is not explicitly set in PSS mode then the signing digest is used.
220
221       rsa_oaep_md:digest
222           Sets the digest used for the OAEP hash function. If not explicitly
223           set then SHA1 is used.
224
225       rsa_pkcs1_implicit_rejection:flag
226           Disables (when set to 0) or enables (when set to 1) the use of
227           implicit rejection with PKCS#1 v1.5 decryption. When enabled (the
228           default), as a protection against Bleichenbacher attack, the
229           library will generate a deterministic random plaintext that it will
230           return to the caller in case of padding check failure.  When
231           disabled, it's the callers' responsibility to handle the returned
232           errors in a side-channel free manner.
233

RSA-PSS ALGORITHM

235       The RSA-PSS algorithm is a restricted version of the RSA algorithm
236       which only supports the sign and verify operations with PSS padding.
237       The following additional -pkeyopt values are supported:
238
239       rsa_padding_mode:mode, rsa_pss_saltlen:len, rsa_mgf1_md:digest
240           These have the same meaning as the RSA algorithm with some
241           additional restrictions. The padding mode can only be set to pss
242           which is the default value.
243
244           If the key has parameter restrictions than the digest, MGF1 digest
245           and salt length are set to the values specified in the parameters.
246           The digest and MG cannot be changed and the salt length cannot be
247           set to a value less than the minimum restriction.
248

DSA ALGORITHM

250       The DSA algorithm supports signing and verification operations only.
251       Currently there are no additional -pkeyopt options other than digest.
252       The SHA1 digest is assumed by default.
253

DH ALGORITHM

255       The DH algorithm only supports the derivation operation and no
256       additional -pkeyopt options.
257

EC ALGORITHM

259       The EC algorithm supports sign, verify and derive operations. The sign
260       and verify operations use ECDSA and derive uses ECDH. SHA1 is assumed
261       by default for the -pkeyopt digest option.
262

X25519 AND X448 ALGORITHMS

264       The X25519 and X448 algorithms support key derivation only. Currently
265       there are no additional options.
266

ED25519 AND ED448 ALGORITHMS

268       These algorithms only support signing and verifying. OpenSSL only
269       implements the "pure" variants of these algorithms so raw data can be
270       passed directly to them without hashing them first. The option -rawin
271       must be used with these algorithms with no -digest specified.
272       Additionally OpenSSL only supports "oneshot" operation with these
273       algorithms. This means that the entire file to be signed/verified must
274       be read into memory before processing it. Signing or Verifying very
275       large files should be avoided. Additionally the size of the file must
276       be known for this to work. If the size of the file cannot be determined
277       (for example if the input is stdin) then the sign or verify operation
278       will fail.
279

SM2

281       The SM2 algorithm supports sign, verify, encrypt and decrypt
282       operations. For the sign and verify operations, SM2 requires an
283       Distinguishing ID string to be passed in. The following -pkeyopt value
284       is supported:
285
286       distid:string
287           This sets the ID string used in SM2 sign or verify operations.
288           While verifying an SM2 signature, the ID string must be the same
289           one used when signing the data.  Otherwise the verification will
290           fail.
291
292       hexdistid:hex_string
293           This sets the ID string used in SM2 sign or verify operations.
294           While verifying an SM2 signature, the ID string must be the same
295           one used when signing the data.  Otherwise the verification will
296           fail. The ID string provided with this option should be a valid
297           hexadecimal value.
298

EXAMPLES

300       Sign some data using a private key:
301
302        openssl pkeyutl -sign -in file -inkey key.pem -out sig
303
304       Recover the signed data (e.g. if an RSA key is used):
305
306        openssl pkeyutl -verifyrecover -in sig -inkey key.pem
307
308       Verify the signature (e.g. a DSA key):
309
310        openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
311
312       Sign data using a message digest value (this is currently only valid
313       for RSA):
314
315        openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
316
317       Derive a shared secret value:
318
319        openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
320
321       Hexdump 48 bytes of TLS1 PRF using digest SHA256 and shared secret and
322       seed consisting of the single byte 0xFF:
323
324        openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \
325           -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump
326
327       Derive a key using scrypt where the password is read from command line:
328
329        openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass \
330           -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1
331
332       Derive using the same algorithm, but read key from environment variable
333       MYPASS:
334
335        openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass:env:MYPASS \
336           -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1
337
338       Sign some data using an SM2(7) private key and a specific ID:
339
340        openssl pkeyutl -sign -in file -inkey sm2.key -out sig -rawin -digest sm3 \
341           -pkeyopt distid:someid
342
343       Verify some data using an SM2(7) certificate and a specific ID:
344
345        openssl pkeyutl -verify -certin -in file -inkey sm2.cert -sigfile sig \
346           -rawin -digest sm3 -pkeyopt distid:someid
347
348       Decrypt some data using a private key with OAEP padding using SHA256:
349
350        openssl pkeyutl -decrypt -in file -inkey key.pem -out secret \
351           -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256
352

SEE ALSO

354       openssl(1), openssl-genpkey(1), openssl-pkey(1), openssl-rsautl(1)
355       openssl-dgst(1), openssl-rsa(1), openssl-genrsa(1), openssl-kdf(1)
356       EVP_PKEY_CTX_set_hkdf_md(3), EVP_PKEY_CTX_set_tls1_prf_md(3),
357

HISTORY

359       The -engine option was deprecated in OpenSSL 3.0.
360
362       Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
363
364       Licensed under the Apache License 2.0 (the "License").  You may not use
365       this file except in compliance with the License.  You can obtain a copy
366       in the file LICENSE in the source distribution or at
367       <https://www.openssl.org/source/license.html>.
368
369
370
3713.0.9                             2023-07-27            OPENSSL-PKEYUTL(1ossl)
Impressum