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