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