Cryptographic hash functions can be used for verifying file integrity. For example, to check that the file has not been altered during transfer over the network. This tutorial explains how to generate a hash of a file using OpenSSL.
Let's say we have the following file named data.txt
:
Hello world
The openssl dgst
command can be used to perform various digest operations. To generate a hash of the file data.txt
using SHA-256, run the following command:
openssl dgst -sha256 data.txt
Output:
SHA256(data.txt)= 64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c
To write result to a file, use -out
option:
openssl dgst -sha256 -out data.sha256 data.txt
To get a list of supported cryptographic hash functions, use the following command:
openssl list --digest-commands
Output example:
blake2b512 blake2s256 gost md4
md5 mdc2 rmd160 sha1
sha224 sha256 sha3-224 sha3-256
sha3-384 sha3-512 sha384 sha512
sha512-224 sha512-256 shake128 shake256
sm3
Leave a Comment
Cancel reply