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