3f1b02ca5154cd27c804ee8c14211c7574a62f11
[openssl.git] / doc / apps / 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<-engine id>]
27 [B<-engine_impl>]
28 [B<file...>]
29
30 B<openssl>
31 [I<digest>]
32 [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 I<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 used by programs like B<sha1sum>.
82
83 =item B<-out filename>
84
85 filename to output to, or standard output by default.
86
87 =item B<-sign filename>
88
89 digitally sign the digest using the private key in "filename".
90
91 =item B<-keyform arg>
92
93 Specifies the key format to sign digest with. The DER, PEM, P12,
94 and ENGINE formats are supported.
95
96 =item B<-sigopt nm:v>
97
98 Pass options to the signature algorithm during sign or verify operations.
99 Names and values of these options are algorithm-specific.
100
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 8
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(s)>
154
155 a file or files containing random data used to seed the random number
156 generator, or an EGD socket (see L<RAND_egd(3)>).
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<-fips-fingerprint>
162
163 compute HMAC using a specific key
164 for certain OpenSSL-FIPS operations.
165
166 =item B<-engine id>
167
168 Use engine B<id> for operations (including private key storage).
169 This engine is not used as source for digest algorithms, unless it is
170 also specified in the configuration file or B<-engine_impl> is also
171 specified.
172
173 =item B<-engine_impl>
174
175 When used with the B<-engine> option, it specifies to also use
176 engine B<id> for digest operations.
177
178 =item B<file...>
179
180 file or files to digest. If no files are specified then standard input is
181 used.
182
183 =back
184
185
186 =head1 EXAMPLES
187
188 To create a hex-encoded message digest of a file:
189  openssl dgst -md5 -hex file.txt
190
191 To sign a file using SHA-256 with binary file output:
192  openssl dgst -sha256 -sign privatekey.pem -out signature.sign file.txt
193
194 To verify a signature:
195  openssl dgst -sha256 -verify publickey.pem \
196  -signature signature.sign \
197  file.txt
198
199
200 =head1 NOTES
201
202 The digest mechanisms that are available will depend on the options
203 used when building OpenSSL.
204 The B<list digest-commands> command can be used to list them.
205
206 New or agile applications should use probably use SHA-256. Other digests,
207 particularly SHA-1 and MD5, are still widely used for interoperating
208 with existing formats and protocols.
209
210 When signing a file, B<dgst> will automatically determine the algorithm
211 (RSA, ECC, etc) to use for signing based on the private key's ASN.1 info.
212 When verifying signatures, it only handles the RSA, DSA, or ECDSA signature
213 itself, not the related data to identify the signer and algorithm used in
214 formats such as x.509, CMS, and S/MIME.
215
216 A source of random numbers is required for certain signing algorithms, in
217 particular ECDSA and DSA.
218
219 The signing and verify options should only be used if a single file is
220 being signed or verified.
221
222 Hex signatures cannot be verified using B<openssl>.  Instead, use "xxd -r"
223 or similar program to transform the hex signature into a binary signature
224 prior to verification.
225
226 =head1 HISTORY
227
228 The default digest was changed from MD5 to SHA256 in OpenSSL 1.1.0
229 The FIPS-related options were removed in OpenSSL 1.1.0
230
231 =head1 COPYRIGHT
232
233 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
234
235 Licensed under the OpenSSL license (the "License").  You may not use
236 this file except in compliance with the License.  You can obtain a copy
237 in the file LICENSE in the source distribution or at
238 L<https://www.openssl.org/source/license.html>.
239
240 =cut