How do I create a message digest using openssl?

The openssl tool has a dgst command which creates message digests. Here’s an example:

$ echo 'hello world' | openssl dgst -sha512 -hex
db3974a97f2407b7cae1ae637c0030687a11913274d578492558e39c16c017de84eacdc8c62fe34ee4e12b4b1428817f09b6a2760c3f8a664ceae94d2434a593

Various flags change the hash algorithm, e.g. -sha1.

A useful flag is -hmac, which lets you sign the content with a shared password:

$ echo 'hello world' | openssl dgst -sha1 -hex -hmac secret_password_1
61c587ccf0d9feebbe95fa866f003a1ae7651f8f
Tagged #hmac, #hashing, #openssl, #cryptography, #programming, #cli.

Similar posts

More by Jim

Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!

This page copyright James Fisher 2017. Content is not associated with my employer. Found an error? Edit this page.