0cbcf850f5d722b82255227279462f3bded90e0e
[openssl.git] / doc / man1 / dgst.pod
1 =pod
2
3 =head1 NAME
4
5 dgst, sha, sha1, mdc2, ripemd160, sha224, sha256, sha384, sha512, md4, md5, blake2b, blake2s - message digests
6
7 =head1 SYNOPSIS
8
9 B<openssl> B<dgst>
10 [B<-help>]
11 [B<-I<digest>>]
12 [B<-c>]
13 [B<-d>]
14 [B<-hex>]
15 [B<-binary>]
16 [B<-r>]
17 [B<-out filename>]
18 [B<-sign filename>]
19 [B<-keyform arg>]
20 [B<-passin arg>]
21 [B<-verify filename>]
22 [B<-prverify filename>]
23 [B<-signature filename>]
24 [B<-hmac key>]
25 [B<-fips-fingerprint>]
26 [B<-rand file...>]
27 [B<-engine id>]
28 [B<-engine_impl>]
29 [B<file...>]
30
31 B<openssl>
32 [I<digest>]
33 [B<...>]
34
35 =head1 DESCRIPTION
36
37 The digest functions output the message digest of a supplied file or files
38 in hexadecimal.  The digest functions also generate and verify digital
39 signatures using message digests.
40
41 The generic name, B<dgst>, may be used with an option specifying the
42 algorithm to be used.
43 The default digest is I<sha256>.
44 A supported I<digest> name may also be used as the command name.
45 To see the list of supported algorithms, use the I<list --digest-commands>
46 command.
47
48 =head1 OPTIONS
49
50 =over 4
51
52 =item B<-help>
53
54 Print out a usage message.
55
56 =item B<-I<digest>>
57
58 Specifies name of a supported digest to be used. To see the list of
59 supported digests, use the command I<list --digest-commands>.
60
61 =item B<-c>
62
63 Print out the digest in two digit groups separated by colons, only relevant if
64 B<hex> format output is used.
65
66 =item B<-d>
67
68 Print out BIO debugging information.
69
70 =item B<-hex>
71
72 Digest is to be output as a hex dump. This is the default case for a "normal"
73 digest as opposed to a digital signature.  See NOTES below for digital
74 signatures using B<-hex>.
75
76 =item B<-binary>
77
78 Output the digest or signature in binary form.
79
80 =item B<-r>
81
82 Output the digest in the "coreutils" format used by programs like B<sha1sum>.
83
84 =item B<-out filename>
85
86 Filename to output to, or standard output by default.
87
88 =item B<-sign filename>
89
90 Digitally sign the digest using the private key in "filename".
91
92 =item B<-keyform 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 nm: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 arg>
103
104 The private key password source. For more information about the format of B<arg>
105 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
106
107 =item B<-verify 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 filename>
113
114 Verify the signature using the private key in "filename".
115
116 =item B<-signature filename>
117
118 The actual signature to verify.
119
120 =item B<-hmac key>
121
122 Create a hashed MAC using "key".
123
124 =item B<-mac alg>
125
126 Create MAC (keyed Message Authentication Code). The most popular MAC
127 algorithm is HMAC (hash-based MAC), but there are other MAC algorithms
128 which are not based on hash, for instance B<gost-mac> algorithm,
129 supported by B<ccgost> engine. MAC keys and other options should be set
130 via B<-macopt> parameter.
131
132 =item B<-macopt nm:v>
133
134 Passes options to MAC algorithm, specified by B<-mac> key.
135 Following options are supported by both by B<HMAC> and B<gost-mac>:
136
137 =over 4
138
139 =item B<key:string>
140
141 Specifies MAC key as alphanumeric string (use if key contain printable
142 characters only). String length must conform to any restrictions of
143 the MAC algorithm for example exactly 32 chars for gost-mac.
144
145 =item B<hexkey:string>
146
147 Specifies MAC key in hexadecimal form (two hex digits per byte).
148 Key length must conform to any restrictions of the MAC algorithm
149 for example exactly 32 chars for gost-mac.
150
151 =back
152
153 =item B<-rand file...>
154
155 A file or files containing random data used to seed the random number
156 generator.
157 Multiple files can be specified separated by an OS-dependent character.
158 The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
159 all others.
160
161 =item [B<-writerand file>]
162
163 Writes random data to the specified I<file> upon exit.
164 This can be used with a subsequent B<-rand> flag.
165
166 =item B<-fips-fingerprint>
167
168 Compute HMAC using a specific key for certain OpenSSL-FIPS operations.
169
170 =item B<-engine id>
171
172 Use engine B<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 B<id> for digest operations.
181
182 =item B<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 B<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, B<dgst> 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 =head1 HISTORY
231
232 The default digest was changed from MD5 to SHA256 in OpenSSL 1.1.0
233 The FIPS-related options were removed in OpenSSL 1.1.0
234
235 =head1 COPYRIGHT
236
237 Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
238
239 Licensed under the OpenSSL license (the "License").  You may not use
240 this file except in compliance with the License.  You can obtain a copy
241 in the file LICENSE in the source distribution or at
242 L<https://www.openssl.org/source/license.html>.
243
244 =cut