5 pkeyutl - public key algorithm utility
15 [B<-keyform PEM|DER|ENGINE>]
18 [B<-peerform PEM|DER|ENGINE>]
30 [B<-pkeyopt opt:value>]
38 The B<pkeyutl> command can be used to perform public key operations using
39 any supported algorithm.
41 =head1 COMMAND OPTIONS
47 Print out a usage message.
51 This specifies the input filename to read data from or standard input
52 if this option is not specified.
54 =item B<-out filename>
56 specifies the output filename to write to or standard output by
59 =item B<-sigfile file>
61 Signature file, required for B<verify> operations only
65 the input key file, by default it should be a private key.
67 =item B<-keyform PEM|DER|ENGINE>
69 the key format PEM, DER or ENGINE. Default is PEM.
73 the input key password source. For more information about the format of B<arg>
74 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
77 =item B<-peerkey file>
79 the peer key file, used by key derivation (agreement) operations.
81 =item B<-peerform PEM|DER|ENGINE>
83 the peer key format PEM, DER or ENGINE. Default is PEM.
87 the input file is a public key.
91 the input is a certificate containing a public key.
95 reverse the order of the input buffer. This is useful for some libraries
96 (such as CryptoAPI) which represent the buffer in little endian format.
100 sign the input data and output the signed result. This requires
105 verify the input data against the signature file and indicate if the
106 verification succeeded or failed.
108 =item B<-verifyrecover>
110 verify the input data and output the recovered data.
114 encrypt the input data using a public key.
118 decrypt the input data using a private key.
122 derive a shared secret using the peer key.
124 =item B<-kdf algorithm>
126 Use key derivation function B<algorithm>. Note: additional paramers
127 will normally have to be set and the KDF output length for this to work.
129 =item B<-kdflen length>
131 Set the ouput length for KDF.
133 =item B<-pkeyopt opt:value>
135 Public key options specified as opt:value. See NOTES below for more details.
139 hex dump the output data.
143 asn1parse the output data, this is useful when combined with the
144 B<-verifyrecover> option when an ASN1 structure is signed.
148 specifying an engine (by its unique B<id> string) will cause B<pkeyutl>
149 to attempt to obtain a functional reference to the specified engine,
150 thus initialising it if needed. The engine will then be set as the default
151 for all available algorithms.
153 =item B<-engine_impl>
155 When used with the B<-engine> option, it specifies to also use
156 engine B<id> for crypto operations.
163 The operations and options supported vary according to the key algorithm
164 and its implementation. The OpenSSL operations and options are indicated below.
166 Unless otherwise mentioned all algorithms support the B<digest:alg> option
167 which specifies the digest in use for sign, verify and verifyrecover operations.
168 The value B<alg> should represent a digest name as used in the
169 EVP_get_digestbyname() function for example B<sha1>.
170 This value is used only for sanity-checking the lengths of data passed in to
171 the B<pkeyutl> and for creating the structures that make up the signature
172 (e.g. B<DigestInfo> in RSASSA PKCS#1 v1.5 signatures).
173 In case of RSA, ECDSA and DSA signatures, this utility
174 will not perform hashing on input data but rather use the data directly as
175 input of signature algorithm. Depending on key type, signature type and mode
176 of padding, the maximum acceptable lengths of input data differ. In general,
177 with RSA the signed data can't be longer than the key modulus, in case of ECDSA
178 and DSA the data shouldn't be longer than field size, otherwise it will be
179 silently truncated to field size.
181 In other words, if the value of digest is B<sha1> the input should be 20 bytes
182 long binary encoding of SHA-1 hash function output.
186 The RSA algorithm generally supports the encrypt, decrypt, sign,
187 verify and verifyrecover operations. However, some padding modes
188 support only a subset of these operations. The following additional
189 B<pkeyopt> values are supported:
193 =item B<rsa_padding_mode:mode>
195 This sets the RSA padding mode. Acceptable values for B<mode> are B<pkcs1> for
196 PKCS#1 padding, B<sslv23> for SSLv23 padding, B<none> for no padding, B<oaep>
197 for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS.
199 In PKCS#1 padding if the message digest is not set then the supplied data is
200 signed or verified directly instead of using a B<DigestInfo> structure. If a
201 digest is set then the a B<DigestInfo> structure is used and its the length
202 must correspond to the digest type.
204 For B<oaep> mode only encryption and decryption is supported.
206 For B<x931> if the digest type is set it is used to format the block data
207 otherwise the first byte is used to specify the X9.31 digest ID. Sign,
208 verify and verifyrecover are can be performed in this mode.
210 For B<pss> mode only sign and verify are supported and the digest type must be
213 =item B<rsa_pss_saltlen:len>
215 For B<pss> mode only this option specifies the salt length. Two special values
216 are supported: -1 sets the salt length to the digest length. When signing -2
217 sets the salt length to the maximum permissible value. When verifying -2 causes
218 the salt length to be automatically determined based on the B<PSS> block
225 The DSA algorithm supports signing and verification operations only. Currently
226 there are no additional options other than B<digest>. Only the SHA1
227 digest can be used and this digest is assumed by default.
231 The DH algorithm only supports the derivation operation and no additional
236 The EC algorithm supports sign, verify and derive operations. The sign and
237 verify operations use ECDSA and derive uses ECDH. Currently there are no
238 additional options other than B<digest>. Only the SHA1 digest can be used and
239 this digest is assumed by default.
243 Sign some data using a private key:
245 openssl pkeyutl -sign -in file -inkey key.pem -out sig
247 Recover the signed data (e.g. if an RSA key is used):
249 openssl pkeyutl -verifyrecover -in sig -inkey key.pem
251 Verify the signature (e.g. a DSA key):
253 openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
255 Sign data using a message digest value (this is currently only valid for RSA):
257 openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
259 Derive a shared secret value:
261 openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
263 Hexdump 48 bytes of TLS1 PRF using digest B<SHA256> and shared secret and
264 seed consisting of the single byte 0xFF.
266 openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \
267 -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump
271 L<genpkey(1)>, L<pkey(1)>, L<rsautl(1)>
272 L<dgst(1)>, L<rsa(1)>, L<genrsa(1)>