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