Sha256 Hashes in Lisp
Here’s the translation of the SHA256 Hashes example from Go to Lisp, formatted in Markdown suitable for Hugo:
In Lisp, we can compute SHA256 hashes using the ironclad
library. SHA256 hashes are frequently used to compute short identities for binary or text blobs. For example, TLS/SSL certificates use SHA256 to compute a certificate’s signature. Here’s how to compute SHA256 hashes in Lisp.
In this Lisp version:
We use the
ironclad
library for cryptographic functions andbabel
for string-to-byte conversion.We define a
main
function that demonstrates the SHA256 hashing process.We create a new SHA256 digest using
ironclad:make-digest :sha256
.The
ironclad:update-digest
function is used to feed the input string (converted to bytes) into the digest.We finalize the hash and get the result using
ironclad:produce-digest
.Finally, we print the original string and the hash in hexadecimal format.
To run the program, save it in a file (e.g., sha256-hashes.lisp
) and use your Lisp interpreter. Make sure you have Quicklisp installed and the required libraries are available.
You can compute other hashes using a similar pattern to the one shown above. For example, to compute SHA512 hashes, you would use :sha512
instead of :sha256
when creating the digest.
Note that if you need cryptographically secure hashes, you should carefully research hash strength!