OPENSSL-DGST(1SSL)

✨ OPENSSL-DGST(1SSL) ✨

okay bestie, sit down, hydrate, because we're about to talk about the OpenSSL openssl-dgst page β€” yes it's also known as openssl-digest and it is literally out here performing digest operations. πŸ’…


🌸 NAME 🌸

openssl-dgst β€” perform digest operations 🫢


πŸŽ€ SYNOPSIS πŸŽ€

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So this command is the moment. It outputs the message digest of a file (or several files, she's versatile) in hexadecimal, AND she also generates and verifies digital signatures using message digests. multitasking queen πŸ‘‘

The generic name, openssl dgst, can be used with an option that tells it which algorithm to use. The default digest is sha256. A supported digest name can also just be the sub-command name itself, because she's chill like that.

Wanna see the whole roster 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 be used. see the -list option down below :
  • -list β€” prints out a list of supported message digests. window shopping fr.
  • -c β€” prints out the digest in two digit groups separated by colons. only relevant if you also gave the -hex option. she's a package deal.
  • -d, -debug β€” print out BIO debugging information. πŸ›
  • -hex β€” the digest gets output 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 β€” output the digest or signature in binary form. no hex, just vibes.
  • -xoflen length β€” set the output length for XOF algorithms, like shake128 and shake256. 🫧 heads up: this option is not supported for signing operations.

For OpenSSL providers, you have to set this value for shake algorithms, because the old default values were only set to supply half of the maximum security strength. not it.

To get 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, which gives you a security strength of only 64 bits.

To get 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, which gives you a security strength of only 128 bits.

  • -r β€” output the digest in the "coreutils" format, including newlines. used by programs like sha1sum(1). she's out here interoperating 🫢
  • -out filename β€” filename to output to, or standard output by default.
  • -sign filename|uri β€” digitally sign the digest using the given private key.
⚠️ real talk: for algorithms that only support one-shot signing (such as 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 β€” the format of the key to sign with; unspecified by default. see openssl-format-options(1) for the deets.
  • -sigopt nm:v β€” pass options to the signature algorithm during sign or verify operations. 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 info about the format of arg, see openssl-passphrase-options(1).
  • -verify filename β€” verify the signature using the public key in filename. the output is either Verified OK or Verification Failure. no in-between, she's decisive. πŸ’…
  • -prverify filename β€” verify the signature using the private key in filename.
  • -signature filename β€” the actual signature to verify.
  • -hmac key β€” create a hashed MAC using key.

Cannot be used together with the -mac option. If multiple -hmac, -hmac-env or -hmac-stdin options are specified, the last one is applied.

The openssl-mac(1) command should be preferred to using this command line option. (she said what she said)

  • -hmac-env var β€” create a hashed MAC using a key from the environment variable var.

Cannot be used together with the -mac option. If multiple -hmac, -hmac-env or -hmac-stdin options are specified, the last one is applied.

The openssl-mac(1) command should be preferred to using this command line option.

  • -hmac-stdin β€” create a hashed MAC using a key obtained from standard input. Only the first line from stdin is read, and the \0 character also terminates the key.

Cannot be used together with the -mac option. If multiple -hmac, -hmac-env or -hmac-stdin options are specified, the last one is applied.

The openssl-mac(1) command should be preferred to using this command line option.

  • -mac alg β€” create a MAC (keyed Message Authentication Code). the most popular MAC algorithm is HMAC (hash-based MAC), but there are other MAC algorithms that are not based on a digest algorithm β€” for instance the gost-mac algorithm, supported by the gostprov provider. MAC keys and other options should be set via the -macopt parameter.

Cannot be used together with -hmac, -hmac-env and -hmac-stdin.

The openssl-mac(1) command should be preferred to using this command line option.

  • -macopt nm:v β€” passes options to the MAC algorithm, specified by the -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.
    • keyenv:var β€” read the MAC key as an alphanumeric string from the environment variable (use this if the key contains printable characters only). the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.
    • keyenvhex:var β€” read the MAC key in hexadecimal form (two hex digits per byte) from the environment variable. the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.
    • keyfile:filename β€” read the MAC key from the specified file. the key is read as binary data. the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.
    • keystdin β€” read the MAC key from standard input. Only the first line from stdin is read, and the \0 character also terminates the key. the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.

If multiple MAC key options are specified, the last one is applied.

The openssl-mac(1) command should be preferred to using this command line option.

  • -fips-fingerprint β€” compute HMAC using a specific key for certain OpenSSL-FIPS operations. πŸ”
  • -rand files, -writerand file β€” see "Random State Options" in openssl(1) for details.
  • -provider name
  • -provider-path path
  • -provparam [name:]key=value
  • -propquery propq β€” see "Provider Options" in openssl(1), provider(7), and property(7).
  • file ... β€” 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 that are available will depend on the options used when building OpenSSL. the openssl list -digest-algorithms command can be used to list them.

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. (iykyk 🫢)

When signing a file, this command will automatically determine 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 don't come for her about that.

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.

⚠️ 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. do not skip this step bestie, it will not work. πŸ’€

The openssl-mac(1) command is preferred over the -hmac, -mac and -macopt command line options.


πŸ”₯ 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 removed in OpenSSL 4.0.

The -hmac-env and -hmac-stdin options were added in OpenSSL 4.0. ✨ glow-up era.


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 πŸ’… mwah. this was OpenSSL 4.0.3, dated 2026-09-29 β€” OPENSSL-DGST(1SSL), stay iconic, drink water, and may your digests always verify. periodt. πŸŒˆπŸ’–πŸ¦‹

πŸ“¦ where this page comes from