5 openssl-dgst - perform digest operations
9 B<openssl> B<dgst>|I<digest>
18 [B<-sign> I<filename>]
21 [B<-verify> I<filename>]
22 [B<-prverify> I<filename>]
23 [B<-signature> I<filename>]
24 [B<-sigopt> I<nm>:I<v>]
26 [B<-fips-fingerprint>]
28 [B<-writerand> I<file>]
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.
39 The generic name, B<openssl dgst>, may be used with an option specifying the
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>
51 Print out a usage message.
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>.
60 Print out the digest in two digit groups separated by colons, only relevant if
61 the B<-hex> option is given as well.
65 Print out BIO debugging information.
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>.
75 Output the digest or signature in binary form.
79 Output the digest in the "coreutils" format, including newlines.
80 Used by programs like L<sha1sum(1)>.
82 =item B<-out> I<filename>
84 Filename to output to, or standard output by default.
86 =item B<-sign> I<filename>
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.
92 =item B<-keyform> I<arg>
94 Specifies the key format to sign digest with. The DER, PEM, P12,
95 and ENGINE formats are supported.
97 =item B<-sigopt> I<nm>:I<v>
99 Pass options to the signature algorithm during sign or verify operations.
100 Names and values of these options are algorithm-specific.
102 =item B<-passin> I<arg>
104 The private key password source. For more information about the format of I<arg>
105 see L<openssl(1)/Pass Phrase Options>.
107 =item B<-verify> I<filename>
109 Verify the signature using the public key in "filename".
110 The output is either "Verification OK" or "Verification Failure".
112 =item B<-prverify> I<filename>
114 Verify the signature using the private key in "filename".
116 =item B<-signature> I<filename>
118 The actual signature to verify.
120 =item B<-hmac> I<key>
122 Create a hashed MAC using "key".
124 The L<openssl-mac(1)> command should be preferred to using this command line
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.
135 The L<openssl-mac(1)> command should be preferred to using this command line
138 =item B<-macopt> I<nm>:I<v>
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>:
145 =item B<key>:I<string>
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.
151 =item B<hexkey>:I<string>
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.
159 The L<openssl-mac(1)> command should be preferred to using this command line
162 =item B<-rand> I<files>, B<-writerand> I<file>
164 See L<openssl(1)/Random State Options> for more information.
166 =item B<-fips-fingerprint>
168 Compute HMAC using a specific key for certain OpenSSL-FIPS operations.
170 =item B<-engine> I<id>
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
177 =item B<-engine_impl>
179 When used with the B<-engine> option, it specifies to also use
180 engine I<id> for digest operations.
184 File or files to digest. If no files are specified then standard input is
192 To create a hex-encoded message digest of a file:
193 openssl dgst -md5 -hex file.txt
195 To sign a file using SHA-256 with binary file output:
196 openssl dgst -sha256 -sign privatekey.pem -out signature.sign file.txt
198 To verify a signature:
199 openssl dgst -sha256 -verify publickey.pem \
200 -signature signature.sign \
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.
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.
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.
220 A source of random numbers is required for certain signing algorithms, in
221 particular ECDSA and DSA.
223 The signing and verify options should only be used if a single file is
224 being signed or verified.
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.
230 The L<openssl-mac(1)> command is preferred over the B<-hmac>, B<-mac> and
231 B<-macopt> command line options.
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.
244 Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
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>.