]> git.ipfire.org Git - thirdparty/openssl.git/blob - doc/man1/openssl-dgst.pod
Refactor many common flags into openssl.pod
[thirdparty/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<-writerand> I<file>]
29 [B<-engine> I<id>]
30 [B<-engine_impl>]
31 [I<file> ...]
32
33 =head1 DESCRIPTION
34
35 This command output the message digest of a supplied file or files
36 in hexadecimal, and also generates and verifies digital
37 signatures using message digests.
38
39 The generic name, B<openssl dgst>, may be used with an option specifying the
40 algorithm to be used.
41 The default digest is B<sha256>.
42 A supported I<digest> name may also be used as the sub-command name.
43 To see the list of supported algorithms, use C<openssl list -digest-commands>
44
45 =head1 OPTIONS
46
47 =over 4
48
49 =item B<-help>
50
51 Print out a usage message.
52
53 =item B<-I<digest>>
54
55 Specifies name of a supported digest to be used. To see the list of
56 supported digests, use the command C<list --digest-commands>.
57
58 =item B<-c>
59
60 Print out the digest in two digit groups separated by colons, only relevant if
61 the B<-hex> option is given as well.
62
63 =item B<-d>
64
65 Print out BIO debugging information.
66
67 =item B<-hex>
68
69 Digest is to be output as a hex dump. This is the default case for a "normal"
70 digest as opposed to a digital signature. See NOTES below for digital
71 signatures using B<-hex>.
72
73 =item B<-binary>
74
75 Output the digest or signature in binary form.
76
77 =item B<-r>
78
79 Output the digest in the "coreutils" format, including newlines.
80 Used by programs like L<sha1sum(1)>.
81
82 =item B<-out> I<filename>
83
84 Filename to output to, or standard output by default.
85
86 =item B<-sign> I<filename>
87
88 Digitally sign the digest using the private key in "filename". Note this option
89 does not support Ed25519 or Ed448 private keys. Use the L<openssl-pkeyutl(1)>
90 command instead for this.
91
92 =item B<-keyform> I<arg>
93
94 Specifies the key format to sign digest with. The DER, PEM, P12,
95 and ENGINE formats are supported.
96
97 =item B<-sigopt> I<nm>:I<v>
98
99 Pass options to the signature algorithm during sign or verify operations.
100 Names and values of these options are algorithm-specific.
101
102 =item B<-passin> I<arg>
103
104 The private key password source. For more information about the format of I<arg>
105 see L<openssl(1)/Pass Phrase Options>.
106
107 =item B<-verify> I<filename>
108
109 Verify the signature using the public key in "filename".
110 The output is either "Verification OK" or "Verification Failure".
111
112 =item B<-prverify> I<filename>
113
114 Verify the signature using the private key in "filename".
115
116 =item B<-signature> I<filename>
117
118 The actual signature to verify.
119
120 =item B<-hmac> I<key>
121
122 Create a hashed MAC using "key".
123
124 The L<openssl-mac(1)> command should be preferred to using this command line
125 option.
126
127 =item B<-mac> I<alg>
128
129 Create MAC (keyed Message Authentication Code). The most popular MAC
130 algorithm is HMAC (hash-based MAC), but there are other MAC algorithms
131 which are not based on hash, for instance B<gost-mac> algorithm,
132 supported by the B<gost> engine. MAC keys and other options should be set
133 via B<-macopt> parameter.
134
135 The L<openssl-mac(1)> command should be preferred to using this command line
136 option.
137
138 =item B<-macopt> I<nm>:I<v>
139
140 Passes options to MAC algorithm, specified by B<-mac> key.
141 Following options are supported by both by B<HMAC> and B<gost-mac>:
142
143 =over 4
144
145 =item B<key>:I<string>
146
147 Specifies MAC key as alphanumeric string (use if key contain printable
148 characters only). String length must conform to any restrictions of
149 the MAC algorithm for example exactly 32 chars for gost-mac.
150
151 =item B<hexkey>:I<string>
152
153 Specifies MAC key in hexadecimal form (two hex digits per byte).
154 Key length must conform to any restrictions of the MAC algorithm
155 for example exactly 32 chars for gost-mac.
156
157 =back
158
159 The L<openssl-mac(1)> command should be preferred to using this command line
160 option.
161
162 =item B<-rand> I<files>, B<-writerand> I<file>
163
164 See L<openssl(1)/Random State Options> for more information.
165
166 =item B<-fips-fingerprint>
167
168 Compute HMAC using a specific key for certain OpenSSL-FIPS operations.
169
170 =item B<-engine> I<id>
171
172 Use engine I<id> for operations (including private key storage).
173 This engine is not used as source for digest algorithms, unless it is
174 also specified in the configuration file or B<-engine_impl> is also
175 specified.
176
177 =item B<-engine_impl>
178
179 When used with the B<-engine> option, it specifies to also use
180 engine I<id> for digest operations.
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