1OPENSSL-PKEYUTL(1ossl) OpenSSL OPENSSL-PKEYUTL(1ossl)
2
3
4
6 openssl-pkeyutl - public key algorithm command
7
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
20 This command can be used to perform low-level public key operations
21 using any supported algorithm.
22
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
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
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 For oaep mode only encryption and decryption is supported.
196
197 For x931 if the digest type is set it is used to format the block
198 data otherwise the first byte is used to specify the X9.31 digest
199 ID. Sign, verify and verifyrecover are can be performed in this
200 mode.
201
202 For pss mode only sign and verify are supported and the digest type
203 must be specified.
204
205 rsa_pss_saltlen:len
206 For pss mode only this option specifies the salt length. Three
207 special values are supported: digest sets the salt length to the
208 digest length, max sets the salt length to the maximum permissible
209 value. When verifying auto causes the salt length to be
210 automatically determined based on the PSS block structure.
211
212 rsa_mgf1_md:digest
213 For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest
214 is not explicitly set in PSS mode then the signing digest is used.
215
216 rsa_oaep_md:digest
217 Sets the digest used for the OAEP hash function. If not explicitly
218 set then SHA1 is used.
219
221 The RSA-PSS algorithm is a restricted version of the RSA algorithm
222 which only supports the sign and verify operations with PSS padding.
223 The following additional -pkeyopt values are supported:
224
225 rsa_padding_mode:mode, rsa_pss_saltlen:len, rsa_mgf1_md:digest
226 These have the same meaning as the RSA algorithm with some
227 additional restrictions. The padding mode can only be set to pss
228 which is the default value.
229
230 If the key has parameter restrictions than the digest, MGF1 digest
231 and salt length are set to the values specified in the parameters.
232 The digest and MG cannot be changed and the salt length cannot be
233 set to a value less than the minimum restriction.
234
236 The DSA algorithm supports signing and verification operations only.
237 Currently there are no additional -pkeyopt options other than digest.
238 The SHA1 digest is assumed by default.
239
241 The DH algorithm only supports the derivation operation and no
242 additional -pkeyopt options.
243
245 The EC algorithm supports sign, verify and derive operations. The sign
246 and verify operations use ECDSA and derive uses ECDH. SHA1 is assumed
247 by default for the -pkeyopt digest option.
248
250 The X25519 and X448 algorithms support key derivation only. Currently
251 there are no additional options.
252
254 These algorithms only support signing and verifying. OpenSSL only
255 implements the "pure" variants of these algorithms so raw data can be
256 passed directly to them without hashing them first. The option -rawin
257 must be used with these algorithms with no -digest specified.
258 Additionally OpenSSL only supports "oneshot" operation with these
259 algorithms. This means that the entire file to be signed/verified must
260 be read into memory before processing it. Signing or Verifying very
261 large files should be avoided. Additionally the size of the file must
262 be known for this to work. If the size of the file cannot be determined
263 (for example if the input is stdin) then the sign or verify operation
264 will fail.
265
267 The SM2 algorithm supports sign, verify, encrypt and decrypt
268 operations. For the sign and verify operations, SM2 requires an
269 Distinguishing ID string to be passed in. The following -pkeyopt value
270 is supported:
271
272 distid:string
273 This sets the ID string used in SM2 sign or verify operations.
274 While verifying an SM2 signature, the ID string must be the same
275 one used when signing the data. Otherwise the verification will
276 fail.
277
278 hexdistid:hex_string
279 This sets the ID string used in SM2 sign or verify operations.
280 While verifying an SM2 signature, the ID string must be the same
281 one used when signing the data. Otherwise the verification will
282 fail. The ID string provided with this option should be a valid
283 hexadecimal value.
284
286 Sign some data using a private key:
287
288 openssl pkeyutl -sign -in file -inkey key.pem -out sig
289
290 Recover the signed data (e.g. if an RSA key is used):
291
292 openssl pkeyutl -verifyrecover -in sig -inkey key.pem
293
294 Verify the signature (e.g. a DSA key):
295
296 openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
297
298 Sign data using a message digest value (this is currently only valid
299 for RSA):
300
301 openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
302
303 Derive a shared secret value:
304
305 openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
306
307 Hexdump 48 bytes of TLS1 PRF using digest SHA256 and shared secret and
308 seed consisting of the single byte 0xFF:
309
310 openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \
311 -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump
312
313 Derive a key using scrypt where the password is read from command line:
314
315 openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass \
316 -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1
317
318 Derive using the same algorithm, but read key from environment variable
319 MYPASS:
320
321 openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass:env:MYPASS \
322 -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1
323
324 Sign some data using an SM2(7) private key and a specific ID:
325
326 openssl pkeyutl -sign -in file -inkey sm2.key -out sig -rawin -digest sm3 \
327 -pkeyopt distid:someid
328
329 Verify some data using an SM2(7) certificate and a specific ID:
330
331 openssl pkeyutl -verify -certin -in file -inkey sm2.cert -sigfile sig \
332 -rawin -digest sm3 -pkeyopt distid:someid
333
334 Decrypt some data using a private key with OAEP padding using SHA256:
335
336 openssl pkeyutl -decrypt -in file -inkey key.pem -out secret \
337 -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256
338
340 openssl(1), openssl-genpkey(1), openssl-pkey(1), openssl-rsautl(1)
341 openssl-dgst(1), openssl-rsa(1), openssl-genrsa(1), openssl-kdf(1)
342 EVP_PKEY_CTX_set_hkdf_md(3), EVP_PKEY_CTX_set_tls1_prf_md(3),
343
345 The -engine option was deprecated in OpenSSL 3.0.
346
348 Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
349
350 Licensed under the Apache License 2.0 (the "License"). You may not use
351 this file except in compliance with the License. You can obtain a copy
352 in the file LICENSE in the source distribution or at
353 <https://www.openssl.org/source/license.html>.
354
355
356
3573.0.5 2022-07-05 OPENSSL-PKEYUTL(1ossl)