openssl-dgst.1ossl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OPENSSL-DGST 1ossl"
  58. .TH OPENSSL-DGST 1ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. openssl\-dgst \- perform digest operations
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. \&\fBopenssl\fR \fBdgst\fR|\fIdigest\fR
  68. [\fB\-\fR\f(BIdigest\fR]
  69. [\fB\-list\fR]
  70. [\fB\-help\fR]
  71. [\fB\-c\fR]
  72. [\fB\-d\fR]
  73. [\fB\-debug\fR]
  74. [\fB\-hex\fR]
  75. [\fB\-binary\fR]
  76. [\fB\-xoflen\fR \fIlength\fR]
  77. [\fB\-r\fR]
  78. [\fB\-out\fR \fIfilename\fR]
  79. [\fB\-sign\fR \fIfilename\fR|\fIuri\fR]
  80. [\fB\-keyform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR]
  81. [\fB\-passin\fR \fIarg\fR]
  82. [\fB\-verify\fR \fIfilename\fR]
  83. [\fB\-prverify\fR \fIfilename\fR]
  84. [\fB\-signature\fR \fIfilename\fR]
  85. [\fB\-sigopt\fR \fInm\fR:\fIv\fR]
  86. [\fB\-hmac\fR \fIkey\fR]
  87. [\fB\-mac\fR \fIalg\fR]
  88. [\fB\-macopt\fR \fInm\fR:\fIv\fR]
  89. [\fB\-fips\-fingerprint\fR]
  90. [\fB\-engine\fR \fIid\fR]
  91. [\fB\-engine_impl\fR \fIid\fR]
  92. [\fB\-rand\fR \fIfiles\fR]
  93. [\fB\-writerand\fR \fIfile\fR]
  94. [\fB\-provider\fR \fIname\fR]
  95. [\fB\-provider\-path\fR \fIpath\fR]
  96. [\fB\-propquery\fR \fIpropq\fR]
  97. [\fIfile\fR ...]
  98. .SH DESCRIPTION
  99. .IX Header "DESCRIPTION"
  100. This command output the message digest of a supplied file or files
  101. in hexadecimal, and also generates and verifies digital
  102. signatures using message digests.
  103. .PP
  104. The generic name, \fBopenssl dgst\fR, may be used with an option specifying the
  105. algorithm to be used.
  106. The default digest is \fBsha256\fR.
  107. A supported \fIdigest\fR name may also be used as the sub-command name.
  108. To see the list of supported algorithms, use \f(CW\*(C`openssl list \-digest\-algorithms\*(C'\fR
  109. .SH OPTIONS
  110. .IX Header "OPTIONS"
  111. .IP \fB\-help\fR 4
  112. .IX Item "-help"
  113. Print out a usage message.
  114. .IP \fB\-\fR\f(BIdigest\fR 4
  115. .IX Item "-digest"
  116. Specifies name of a supported digest to be used. See option \fB\-list\fR below :
  117. .IP \fB\-list\fR 4
  118. .IX Item "-list"
  119. Prints out a list of supported message digests.
  120. .IP \fB\-c\fR 4
  121. .IX Item "-c"
  122. Print out the digest in two digit groups separated by colons, only relevant if
  123. the \fB\-hex\fR option is given as well.
  124. .IP "\fB\-d\fR, \fB\-debug\fR" 4
  125. .IX Item "-d, -debug"
  126. Print out BIO debugging information.
  127. .IP \fB\-hex\fR 4
  128. .IX Item "-hex"
  129. Digest is to be output as a hex dump. This is the default case for a "normal"
  130. digest as opposed to a digital signature. See NOTES below for digital
  131. signatures using \fB\-hex\fR.
  132. .IP \fB\-binary\fR 4
  133. .IX Item "-binary"
  134. Output the digest or signature in binary form.
  135. .IP "\fB\-xoflen\fR \fIlength\fR" 4
  136. .IX Item "-xoflen length"
  137. Set the output length for XOF algorithms, such as \fBshake128\fR and \fBshake256\fR.
  138. This option is not supported for signing operations.
  139. .Sp
  140. For OpenSSL providers it is recommended to set this value for shake algorithms,
  141. since the default values are set to only supply half of the maximum security
  142. strength.
  143. .Sp
  144. For backwards compatibility reasons the default xoflen length for \fBshake128\fR is
  145. 16 (bytes) which results in a security strength of only 64 bits. To ensure the
  146. maximum security strength of 128 bits, the xoflen should be set to at least 32.
  147. .Sp
  148. For backwards compatibility reasons the default xoflen length for \fBshake256\fR is
  149. 32 (bytes) which results in a security strength of only 128 bits. To ensure the
  150. maximum security strength of 256 bits, the xoflen should be set to at least 64.
  151. .IP \fB\-r\fR 4
  152. .IX Item "-r"
  153. Output the digest in the "coreutils" format, including newlines.
  154. Used by programs like \fBsha1sum\fR\|(1).
  155. .IP "\fB\-out\fR \fIfilename\fR" 4
  156. .IX Item "-out filename"
  157. Filename to output to, or standard output by default.
  158. .IP "\fB\-sign\fR \fIfilename\fR|\fIuri\fR" 4
  159. .IX Item "-sign filename|uri"
  160. Digitally sign the digest using the given private key. Note this option
  161. does not support Ed25519 or Ed448 private keys. Use the \fBopenssl\-pkeyutl\fR\|(1)
  162. command instead for this.
  163. .IP "\fB\-keyform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR" 4
  164. .IX Item "-keyform DER|PEM|P12|ENGINE"
  165. The format of the key to sign with; unspecified by default.
  166. See \fBopenssl\-format\-options\fR\|(1) for details.
  167. .IP "\fB\-sigopt\fR \fInm\fR:\fIv\fR" 4
  168. .IX Item "-sigopt nm:v"
  169. Pass options to the signature algorithm during sign or verify operations.
  170. Names and values of these options are algorithm-specific and documented
  171. in "Signature parameters" in \fBprovider\-signature\fR\|(7).
  172. .IP "\fB\-passin\fR \fIarg\fR" 4
  173. .IX Item "-passin arg"
  174. The private key password source. For more information about the format of \fIarg\fR
  175. see \fBopenssl\-passphrase\-options\fR\|(1).
  176. .IP "\fB\-verify\fR \fIfilename\fR" 4
  177. .IX Item "-verify filename"
  178. Verify the signature using the public key in "filename".
  179. The output is either "Verified OK" or "Verification Failure".
  180. .IP "\fB\-prverify\fR \fIfilename\fR" 4
  181. .IX Item "-prverify filename"
  182. Verify the signature using the private key in "filename".
  183. .IP "\fB\-signature\fR \fIfilename\fR" 4
  184. .IX Item "-signature filename"
  185. The actual signature to verify.
  186. .IP "\fB\-hmac\fR \fIkey\fR" 4
  187. .IX Item "-hmac key"
  188. Create a hashed MAC using "key".
  189. .Sp
  190. The \fBopenssl\-mac\fR\|(1) command should be preferred to using this command line
  191. option.
  192. .IP "\fB\-mac\fR \fIalg\fR" 4
  193. .IX Item "-mac alg"
  194. Create MAC (keyed Message Authentication Code). The most popular MAC
  195. algorithm is HMAC (hash-based MAC), but there are other MAC algorithms
  196. which are not based on hash, for instance \fBgost-mac\fR algorithm,
  197. supported by the \fBgost\fR engine. MAC keys and other options should be set
  198. via \fB\-macopt\fR parameter.
  199. .Sp
  200. The \fBopenssl\-mac\fR\|(1) command should be preferred to using this command line
  201. option.
  202. .IP "\fB\-macopt\fR \fInm\fR:\fIv\fR" 4
  203. .IX Item "-macopt nm:v"
  204. Passes options to MAC algorithm, specified by \fB\-mac\fR key.
  205. Following options are supported by both by \fBHMAC\fR and \fBgost-mac\fR:
  206. .RS 4
  207. .IP \fBkey\fR:\fIstring\fR 4
  208. .IX Item "key:string"
  209. Specifies MAC key as alphanumeric string (use if key contain printable
  210. characters only). String length must conform to any restrictions of
  211. the MAC algorithm for example exactly 32 chars for gost-mac.
  212. .IP \fBhexkey\fR:\fIstring\fR 4
  213. .IX Item "hexkey:string"
  214. Specifies MAC key in hexadecimal form (two hex digits per byte).
  215. Key length must conform to any restrictions of the MAC algorithm
  216. for example exactly 32 chars for gost-mac.
  217. .RE
  218. .RS 4
  219. .Sp
  220. The \fBopenssl\-mac\fR\|(1) command should be preferred to using this command line
  221. option.
  222. .RE
  223. .IP \fB\-fips\-fingerprint\fR 4
  224. .IX Item "-fips-fingerprint"
  225. Compute HMAC using a specific key for certain OpenSSL-FIPS operations.
  226. .IP "\fB\-rand\fR \fIfiles\fR, \fB\-writerand\fR \fIfile\fR" 4
  227. .IX Item "-rand files, -writerand file"
  228. See "Random State Options" in \fBopenssl\fR\|(1) for details.
  229. .IP "\fB\-engine\fR \fIid\fR" 4
  230. .IX Item "-engine id"
  231. See "Engine Options" in \fBopenssl\fR\|(1).
  232. This option is deprecated.
  233. .Sp
  234. The engine is not used for digests unless the \fB\-engine_impl\fR option is
  235. used or it is configured to do so, see "Engine Configuration Module" in \fBconfig\fR\|(5).
  236. .IP "\fB\-engine_impl\fR \fIid\fR" 4
  237. .IX Item "-engine_impl id"
  238. When used with the \fB\-engine\fR option, it specifies to also use
  239. engine \fIid\fR for digest operations.
  240. .IP "\fB\-provider\fR \fIname\fR" 4
  241. .IX Item "-provider name"
  242. .PD 0
  243. .IP "\fB\-provider\-path\fR \fIpath\fR" 4
  244. .IX Item "-provider-path path"
  245. .IP "\fB\-propquery\fR \fIpropq\fR" 4
  246. .IX Item "-propquery propq"
  247. .PD
  248. See "Provider Options" in \fBopenssl\fR\|(1), \fBprovider\fR\|(7), and \fBproperty\fR\|(7).
  249. .IP "\fIfile\fR ..." 4
  250. .IX Item "file ..."
  251. File or files to digest. If no files are specified then standard input is
  252. used.
  253. .SH EXAMPLES
  254. .IX Header "EXAMPLES"
  255. To create a hex-encoded message digest of a file:
  256. .PP
  257. .Vb 3
  258. \& openssl dgst \-md5 \-hex file.txt
  259. \& or
  260. \& openssl md5 file.txt
  261. .Ve
  262. .PP
  263. To sign a file using SHA\-256 with binary file output:
  264. .PP
  265. .Vb 3
  266. \& openssl dgst \-sha256 \-sign privatekey.pem \-out signature.sign file.txt
  267. \& or
  268. \& openssl sha256 \-sign privatekey.pem \-out signature.sign file.txt
  269. .Ve
  270. .PP
  271. To verify a signature:
  272. .PP
  273. .Vb 3
  274. \& openssl dgst \-sha256 \-verify publickey.pem \e
  275. \& \-signature signature.sign \e
  276. \& file.txt
  277. .Ve
  278. .SH NOTES
  279. .IX Header "NOTES"
  280. The digest mechanisms that are available will depend on the options
  281. used when building OpenSSL.
  282. The \f(CW\*(C`openssl list \-digest\-algorithms\*(C'\fR command can be used to list them.
  283. .PP
  284. New or agile applications should use probably use SHA\-256. Other digests,
  285. particularly SHA\-1 and MD5, are still widely used for interoperating
  286. with existing formats and protocols.
  287. .PP
  288. When signing a file, this command will automatically determine the algorithm
  289. (RSA, ECC, etc) to use for signing based on the private key's ASN.1 info.
  290. When verifying signatures, it only handles the RSA, DSA, or ECDSA signature
  291. itself, not the related data to identify the signer and algorithm used in
  292. formats such as x.509, CMS, and S/MIME.
  293. .PP
  294. A source of random numbers is required for certain signing algorithms, in
  295. particular ECDSA and DSA.
  296. .PP
  297. The signing and verify options should only be used if a single file is
  298. being signed or verified.
  299. .PP
  300. Hex signatures cannot be verified using \fBopenssl\fR. Instead, use "xxd \-r"
  301. or similar program to transform the hex signature into a binary signature
  302. prior to verification.
  303. .PP
  304. The \fBopenssl\-mac\fR\|(1) command is preferred over the \fB\-hmac\fR, \fB\-mac\fR and
  305. \&\fB\-macopt\fR command line options.
  306. .SH "SEE ALSO"
  307. .IX Header "SEE ALSO"
  308. \&\fBopenssl\-mac\fR\|(1)
  309. .SH HISTORY
  310. .IX Header "HISTORY"
  311. The default digest was changed from MD5 to SHA256 in OpenSSL 1.1.0.
  312. The FIPS-related options were removed in OpenSSL 1.1.0.
  313. .PP
  314. The \fB\-engine\fR and \fB\-engine_impl\fR options were deprecated in OpenSSL 3.0.
  315. .SH COPYRIGHT
  316. .IX Header "COPYRIGHT"
  317. Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
  318. .PP
  319. Licensed under the Apache License 2.0 (the "License"). You may not use
  320. this file except in compliance with the License. You can obtain a copy
  321. in the file LICENSE in the source distribution or at
  322. <https://www.openssl.org/source/license.html>.