OPENSSL-DGST(1ossl)
π 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-listbelow : (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.-xoflenlength β sets the output length for XOF algorithms, likeshake128andshake256. 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 likesha1sum(1)use π«Ά-outfilename β the filename to output to, or standard output by default.-signfilename|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. seeopenssl-format-options(1)for the deets.-sigoptnm: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" inprovider-signature(7).-passinarg β the private key password source. for more on the format of arg, seeopenssl-passphrase-options(1).-verifyfilename β verifies the signature using the public key in "filename". the output is eitherVerified OKorVerification Failure. (praying for the first one π)-prverifyfilename β verifies the signature using the private key in "filename".-signaturefilename β the actual signature to verify.-hmackey β 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?)
-macalg β 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 thegost-macalgorithm, supported by the gost engine. MAC keys and other options should be set via the-macoptparameter.
the openssl-mac(1) command should be preferred over using this command line option.
-macoptnm:v β passes options to the MAC algorithm specified by-mackey. the following options are supported by both HMAC andgost-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 exactly32chars forgost-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 exactly32chars forgost-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.-randfiles,-writerandfile β see "Random State Options" inopenssl(1)for details.-engineid β see "Engine Options" inopenssl(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_implid β when used with the-engineoption, it specifies to also use engine id for digest operations.-providername-provider-pathpath-provparam[name:]key=value-propquerypropq
(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 usingopenssl. instead, usexxd -ror 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 π
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
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms