Hashes and Message Authentication Codes

Index

Hash generation

OpenSSL also has features for generating hashes of various types.

Generate hash of a file

Using SHA1

openssl sha1 <FILE> 

SHA1(<FILE>)= 95e91837dc1a4a8eeb42208420d8620cb8d7785f

Using SHA256

openssl sha256 <FILE> 

SHA256(<FILE>)= b110ed205353743923c7d66811a2916e2cc3bb3a06e7411e79a4b124ca1322d0

Using RIPEMD160

It is also possible to use the openssl dgst command to create hashes from data.

Listing the available hash functions

To list the available hash functions, simply do:

This will present all the hash functions that are supported by openssl:

Create a hash from a file

To create a hash from a specific file, we need to do:

That produces the appropriate value:

Create a hash with a "salt"

The following command will create a hash value from a password (mypassword) with a "salt" value (mysaltvalue) - using the SHA256:

Generate a Message Authentication Code

In order to generate a hash-based message authentication code, we need to provide the hash algorithm to be used and the secret key to encrypt the hash.

Last updated