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