OPENSSL-DGST(1ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… OPENSSL-DGST β€” perform digest operations ✨

okay bestie, so this page is openssl-dgst from the OpenSSL manual (that's the 1ossl manual name, iykyk) β€” and it's literally the glow-up tutorial for hashing files and signing stuff. let's go πŸŽ€


🌸 SYNOPSIS 🌸

openssl dgst|digest [-digest] [-list] [-help] [-c] [-d] [-debug] [-hex]
[-binary] [-xoflen length] [-r] [-out filename] [-sign filename|uri]
[-keyform DER|PEM|P12|ENGINE] [-passin arg] [-verify filename]
[-prverify filename] [-signature filename] [-sigopt nm:v] [-hmac key]
[-mac alg] [-macopt nm:v] [-fips-fingerprint] [-engine id] [-engine_impl
id] [-rand files] [-writerand file] [-provider name] [-provider-path
path] [-provparam [name:]key=value] [-propquery propq] [file ...]

✨ DESCRIPTION ✨

So this command prints the message digest of a file (or files) you hand it, in hexadecimal β€” and it also generates and verifies digital signatures using message digests. it's giving two-jobs-one-icon πŸ’…

The generic name, openssl dgst, is what you use together with an option that says which algorithm you want. the default digest is sha256. a supported digest name can also just be the sub-command name directly (main character energy fr). and if you wanna see the whole list of supported algorithms, run openssl list -digest-algorithms πŸ¦‹


πŸ’– OPTIONS πŸ’–

  • -help β€” prints out a usage message. classic.
  • -digest β€” specifies the name of a supported digest to use. see -list below : (yes the colon is part of the vibe)
  • -list β€” prints out a list of supported message digests. window shopping bestie πŸ›οΈ
  • -c β€” prints the digest in two-digit groups separated by colons β€” but only relevant if you also gave -hex. no -hex, no colon cuteness.
  • -d, -debug β€” prints out BIO debugging information.
  • -hex β€” output the digest as a hex dump. this is the default case for a "normal" digest, as opposed to a digital signature. (peep NOTES below for digital signatures using -hex πŸ‘€)
  • -binary β€” outputs the digest or signature in binary form.
  • -xoflen length β€” sets the output length for XOF algorithms, like shake128 and shake256. this option is not supported for signing operations.

For OpenSSL providers it's required to set this value for shake algorithms, since the previous default values were only set to supply half of the maximum security strength. (they really said "half is enough" 😭)

To ensure the maximum security strength of 128 bits, the xoflen for shake128 should be set to at least 32 (bytes). for compatibility with previous versions of OpenSSL, it may be set to 16, resulting in a security strength of only 64 bits.

To ensure the maximum security strength of 256 bits, the xoflen for shake256 should be set to at least 64 (bytes). for compatibility with previous versions of OpenSSL, it may be set to 32, resulting in a security strength of only 128 bits.

  • -r β€” outputs the digest in the "coreutils" format, including newlines. this is the one programs like sha1sum(1) use 🫢
  • -out filename β€” the filename to output to, or standard output by default.
  • -sign filename|uri β€” digitally signs the digest using the given private key.

bestie, heads up: for algorithms that only support one-shot signing (like Ed25519, ED448, ML-DSA-44, ML-DSA-65 and ML-DSA-87) the digest must not be set. for these algorithms the input is buffered (and not digested) before signing. and for these algorithms, if the input is larger than 16MB an error will occur. 😭

  • -keyform DER|PEM|P12|ENGINE β€” the format of the key to sign with; unspecified by default. see openssl-format-options(1) for the deets.
  • -sigopt nm:v β€” passes options to the signature algorithm during sign or verify operations. the names and values of these options are algorithm-specific and documented in "Signature parameters" in provider-signature(7).
  • -passin arg β€” the private key password source. for more on the format of arg, see openssl-passphrase-options(1).
  • -verify filename β€” verifies the signature using the public key in "filename". the output is either Verified OK or Verification Failure. (praying for the first one πŸ™)
  • -prverify filename β€” verifies the signature using the private key in "filename".
  • -signature filename β€” the actual signature to verify.
  • -hmac key β€” creates a hashed MAC using "key".
the openssl-mac(1) command should be preferred over using this command line option. (like, the newer one ate, ok?)
  • -mac alg β€” creates a MAC (keyed Message Authentication Code). the most popular MAC algorithm is HMAC (hash-based MAC), but there are other MAC algorithms which are not based on hash β€” for instance the gost-mac algorithm, supported by the gost engine. MAC keys and other options should be set via the -macopt parameter.
the openssl-mac(1) command should be preferred over using this command line option.
  • -macopt nm:v β€” passes options to the MAC algorithm specified by -mac key. the following options are supported by both HMAC and gost-mac:
    • key:string β€” specifies the MAC key as an alphanumeric string (use this if the key contains printable characters only). the string length must conform to any restrictions of the MAC algorithm β€” for example exactly 32 chars for gost-mac.
    • hexkey:string β€” specifies the MAC key in hexadecimal form (two hex digits per byte). the key length must conform to any restrictions of the MAC algorithm β€” for example exactly 32 chars for gost-mac.
the openssl-mac(1) command should be preferred over using this command line option. (third time's the charm πŸ’€)
  • -fips-fingerprint β€” computes HMAC using a specific key for certain OpenSSL-FIPS operations.
  • -rand files, -writerand file β€” see "Random State Options" in openssl(1) for details.
  • -engine id β€” see "Engine Options" in openssl(1). this option is deprecated 🚩

the engine is not used for digests unless the -engine_impl option is used, or it's configured to do so β€” see "Engine Configuration Module" in config(5).

  • -engine_impl id β€” when used with the -engine option, it specifies to also use engine id for digest operations.
  • -provider name
  • -provider-path path
  • -provparam [name:]key=value
  • -propquery propq

(those last four: see "Provider Options" in openssl(1), provider(7), and property(7). yes they're grouped, yes they slay together πŸ’œ)

  • file ... β€” the file or files to digest. if no files are specified, then standard input is used.

πŸ¦‹ EXAMPLES πŸ¦‹

To create a hex-encoded message digest of a file:

openssl dgst -md5 -hex file.txt
or
openssl md5 file.txt

To sign a file using SHA-256 with binary file output:

openssl dgst -sha256 -sign privatekey.pem -out signature.sign file.txt
or
openssl sha256 -sign privatekey.pem -out signature.sign file.txt

To verify a signature:

openssl dgst -sha256 -verify publickey.pem \
-signature signature.sign \
file.txt

πŸ”₯ NOTES πŸ”₯

The digest mechanisms available will depend on the options used when building OpenSSL. the openssl list -digest-algorithms command can be used to list them all πŸ‘‘

New or agile applications should probably use SHA-256. other digests β€” particularly SHA-1 and MD5 β€” are still widely used for interoperating with existing formats and protocols. (they're not cancelled, they're just legacy core 😌)

When signing a file, this command automatically determines the algorithm (RSA, ECC, etc) to use for signing, based on the private key's ASN.1 info. When verifying signatures, it only handles the RSA, DSA, or ECDSA signature itself β€” not the related data to identify the signer and algorithm used in formats such as x.509, CMS, and S/MIME. (so like, it does the signature part, not the whole personality)

A source of random numbers is required for certain signing algorithms, in particular ECDSA and DSA. 🎲

The signing and verify options should only be used if a single file is being signed or verified. one file. that's it. don't push it.
Hex signatures cannot be verified using openssl. instead, use xxd -r or a similar program to transform the hex signature into a binary signature prior to verification. important!! πŸ™ˆ

The openssl-mac(1) command is preferred over the -hmac, -mac and -macopt command line options. (fourth time. they're committed.)


🌈 SEE ALSO 🌈


⭐ HISTORY ⭐

The default digest was changed from MD5 to SHA256 in OpenSSL 1.1.0. the FIPS-related options were removed in OpenSSL 1.1.0.

The -engine and -engine_impl options were deprecated in OpenSSL 3.0. 🫑


Copyright 2000-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page bestie, no cap πŸ’– this one's from the 3.5.0 era, dated 2026-09-25 β€” go forth and digest, periodt πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from