LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

openssl-dgst

perform message digest operations

TLDR

Calculate SHA256 hash of a file
$ openssl dgst -sha256 [file]
copy
Calculate MD5 hash
$ openssl dgst -md5 [file]
copy
Output hash in coreutils-compatible format
$ openssl dgst -sha256 -r [file]
copy
Calculate hash and write output to a file
$ openssl dgst -sha256 -out [hash.txt] [file]
copy
Create an HMAC using a key
$ openssl dgst -sha256 -hmac "[secret_key]" [file]
copy
Sign a file with a private key
$ openssl dgst -sha256 -sign [private.pem] -out [signature.bin] [file]
copy
Verify a signature with a public key
$ openssl dgst -sha256 -verify [public.pem] -signature [signature.bin] [file]
copy

SYNOPSIS

openssl dgst [options] [file...]

DESCRIPTION

openssl dgst outputs the message digest of files in hexadecimal form. It supports various algorithms including SHA-256, SHA-512, SHA-384, SHA-1, and MD5. Can also generate and verify digital signatures using asymmetric keys, and create HMACs. If no files are specified, standard input is used.

PARAMETERS

-sha256, -sha512, -sha384, -sha1, -md5

Hash algorithm to use. Default is sha256.
-sign keyfile
Sign the digest using the private key in the specified file.
-verify keyfile
Verify the signature using the public key in the specified file.
-prverify keyfile
Verify the signature using the private key in the specified file.
-signature file
The signature file to verify against.
-hmac key
Create a hashed MAC using the given key.
-out filename
Output filename. Default is standard output.
-r
Output hash in coreutils-compatible format.
-hex
Output as hex dump (default).
-binary
Output the digest in binary form.
-c
Print the digest in two-digit groups separated by colons.
-keyform arg
Key format: PEM, DER, P12, or ENGINE.
-passin arg
Private key password source.
-sigopt nm:v
Pass options to the signature algorithm during sign or verify.
-list
Print a list of supported digest algorithms.

SEE ALSO

Copied to clipboard
Kai