Refactor -passin/-passout documentation
[openssl.git] / doc / man1 / openssl-dgst.pod
1 =pod
2
3 =head1 NAME
4
5 openssl-dgst - perform digest operations
6
7 =head1 SYNOPSIS
8
9 B<openssl> B<dgst>|I<digest>
10 [B<-I<digest>>]
11 [B<-help>]
12 [B<-c>]
13 [B<-d>]
14 [B<-hex>]
15 [B<-binary>]
16 [B<-r>]
17 [B<-out> I<filename>]
18 [B<-sign> I<filename>]
19 [B<-keyform> I<arg>]
20 [B<-passin> I<arg>]
21 [B<-verify> I<filename>]
22 [B<-prverify> I<filename>]
23 [B<-signature> I<filename>]
24 [B<-sigopt> I<nm>:I<v>]
25 [B<-hmac> I<key>]
26 [B<-fips-fingerprint>]
27 [B<-rand> I<files>]
28 [B<-engine> I<id>]
29 [B<-engine_impl>]
30 [I<file> ...]
31
32 =head1 DESCRIPTION
33
34 This command output the message digest of a supplied file or files
35 in hexadecimal, and also generates and verifies digital
36 signatures using message digests.
37
38 The generic name, B<openssl dgst>, may be used with an option specifying the
39 algorithm to be used.
40 The default digest is B<sha256>.
41 A supported I<digest> name may also be used as the sub-command name.
42 To see the list of supported algorithms, use C<openssl list -digest-commands>
43
44 =head1 OPTIONS
45
46 =over 4
47
48 =item B<-help>
49
50 Print out a usage message.
51
52 =item B<-I<digest>>
53
54 Specifies name of a supported digest to be used. To see the list of
55 supported digests, use the command C<list --digest-commands>.
56
57 =item B<-c>
58
59 Print out the digest in two digit groups separated by colons, only relevant if
60 the B<-hex> option is given as well.
61
62 =item B<-d>
63
64 Print out BIO debugging information.
65
66 =item B<-hex>
67
68 Digest is to be output as a hex dump. This is the default case for a "normal"
69 digest as opposed to a digital signature.  See NOTES below for digital
70 signatures using B<-hex>.
71
72 =item B<-binary>
73
74 Output the digest or signature in binary form.
75
76 =item B<-r>
77
78 Output the digest in the "coreutils" format, including newlines.
79 Used by programs like L<sha1sum(1)>.
80
81 =item B<-out> I<filename>
82
83 Filename to output to, or standard output by default.
84
85 =item B<-sign> I<filename>
86
87 Digitally sign the digest using the private key in "filename". Note this option
88 does not support Ed25519 or Ed448 private keys. Use the L<openssl-pkeyutl(1)>
89 command instead for this.
90
91 =item B<-keyform> I<arg>
92
93 Specifies the key format to sign digest with. The DER, PEM, P12,
94 and ENGINE formats are supported.
95
96 =item B<-sigopt> I<nm>:I<v>
97
98 Pass options to the signature algorithm during sign or verify operations.
99 Names and values of these options are algorithm-specific.
100
101 =item B<-passin> I<arg>
102
103 The private key password source. For more information about the format of I<arg>
104 see L<openssl(1)/Pass Phrase Options>.
105
106 =item B<-verify> I<filename>
107
108 Verify the signature using the public key in "filename".
109 The output is either "Verification OK" or "Verification Failure".
110
111 =item B<-prverify> I<filename>
112
113 Verify the signature using the private key in "filename".
114
115 =item B<-signature> I<filename>
116
117 The actual signature to verify.
118
119 =item B<-hmac> I<key>
120
121 Create a hashed MAC using "key".
122
123 The L<openssl-mac(1)> command should be preferred to using this command line
124 option.
125
126 =item B<-mac> I<alg>
127
128 Create MAC (keyed Message Authentication Code). The most popular MAC
129 algorithm is HMAC (hash-based MAC), but there are other MAC algorithms
130 which are not based on hash, for instance B<gost-mac> algorithm,
131 supported by the B<gost> engine. MAC keys and other options should be set
132 via B<-macopt> parameter.
133
134 The L<openssl-mac(1)> command should be preferred to using this command line
135 option.
136
137 =item B<-macopt> I<nm>:I<v>
138
139 Passes options to MAC algorithm, specified by B<-mac> key.
140 Following options are supported by both by B<HMAC> and B<gost-mac>:
141
142 =over 4
143
144 =item B<key>:I<string>
145
146 Specifies MAC key as alphanumeric string (use if key contain printable
147 characters only). String length must conform to any restrictions of
148 the MAC algorithm for example exactly 32 chars for gost-mac.
149
150 =item B<hexkey>:I<string>
151
152 Specifies MAC key in hexadecimal form (two hex digits per byte).
153 Key length must conform to any restrictions of the MAC algorithm
154 for example exactly 32 chars for gost-mac.
155
156 =back
157
158 The L<openssl-mac(1)> command should be preferred to using this command line
159 option.
160
161 =item B<-rand> I<files>
162
163 The files containing random data used to seed the random number generator.
164 Multiple files can be specified separated by an OS-dependent character.
165 The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
166 all others.
167
168 =item B<-writerand> I<file>
169
170 Writes random data to the specified I<file> upon exit.
171 This can be used with a subsequent B<-rand> flag.
172
173 =item B<-fips-fingerprint>
174
175 Compute HMAC using a specific key for certain OpenSSL-FIPS operations.
176
177 =item B<-engine> I<id>
178
179 Use engine I<id> for operations (including private key storage).
180 This engine is not used as source for digest algorithms, unless it is
181 also specified in the configuration file or B<-engine_impl> is also
182 specified.
183
184 =item B<-engine_impl>
185
186 When used with the B<-engine> option, it specifies to also use
187 engine I<id> for digest operations.
188
189 =item I<file> ...
190
191 File or files to digest. If no files are specified then standard input is
192 used.
193
194 =back
195
196
197 =head1 EXAMPLES
198
199 To create a hex-encoded message digest of a file:
200  openssl dgst -md5 -hex file.txt
201
202 To sign a file using SHA-256 with binary file output:
203  openssl dgst -sha256 -sign privatekey.pem -out signature.sign file.txt
204
205 To verify a signature:
206  openssl dgst -sha256 -verify publickey.pem \
207  -signature signature.sign \
208  file.txt
209
210
211 =head1 NOTES
212
213 The digest mechanisms that are available will depend on the options
214 used when building OpenSSL.
215 The C<openssl list -digest-commands> command can be used to list them.
216
217 New or agile applications should use probably use SHA-256. Other digests,
218 particularly SHA-1 and MD5, are still widely used for interoperating
219 with existing formats and protocols.
220
221 When signing a file, this command will automatically determine the algorithm
222 (RSA, ECC, etc) to use for signing based on the private key's ASN.1 info.
223 When verifying signatures, it only handles the RSA, DSA, or ECDSA signature
224 itself, not the related data to identify the signer and algorithm used in
225 formats such as x.509, CMS, and S/MIME.
226
227 A source of random numbers is required for certain signing algorithms, in
228 particular ECDSA and DSA.
229
230 The signing and verify options should only be used if a single file is
231 being signed or verified.
232
233 Hex signatures cannot be verified using B<openssl>.  Instead, use "xxd -r"
234 or similar program to transform the hex signature into a binary signature
235 prior to verification.
236
237 The L<openssl-mac(1)> command is preferred over the B<-hmac>, B<-mac> and
238 B<-macopt> command line options.
239
240 =head1 SEE ALSO
241
242 L<openssl-mac(1)>
243
244 =head1 HISTORY
245
246 The default digest was changed from MD5 to SHA256 in OpenSSL 1.1.0.
247 The FIPS-related options were removed in OpenSSL 1.1.0.
248
249 =head1 COPYRIGHT
250
251 Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
252
253 Licensed under the Apache License 2.0 (the "License").  You may not use
254 this file except in compliance with the License.  You can obtain a copy
255 in the file LICENSE in the source distribution or at
256 L<https://www.openssl.org/source/license.html>.
257
258 =cut