Liking cljdoc? Tell your friends :D

digest

net.clojars.savya/digest - A message digest library for Clojure. Providing md5, sha-256, HMAC, raw bytes, and base64 output.

Stack

Clojure GitHub Actions

Clojars Project cljdoc badge CI

There are several digest functions (such as md5, sha-256 ...) in this namespace. Each can handle the following input types:

  • java.lang.String
  • byte array
  • java.io.File
  • java.io.InputStream
  • Sequence of byte array

String encoding (behavior change in 1.5.0)

Strings are encoded as UTF-8 before hashing. Earlier releases (1.4.x and before) used the JVM's default charset, so on a JVM whose default was not UTF-8 the same string produced a different digest. As of 1.5.0 the output is stable regardless of platform default. If you need to reproduce a hash computed by an older release on a non-UTF-8 JVM, pass the encoding explicitly: (digest/digest "md5" s "ISO-8859-1").

Usage

user=> (require '[clj-commons.digest :as digest])
nil
; On a string
user=> (digest/md5 "clojure")
"32c0d97f82a20e67c6d184620f6bd322"
; On a file
user=> (require '[clojure.java.io :as io])
nil
user=> (digest/sha-256 (io/file "/tmp/hello.txt"))
"163883d3e0e3b0c028d35b626b98564be8d9d649ed8adb8b929cb8c94c735c59"
; Raw bytes
user=> (seq (digest/digest-bytes "MD5" "clojure"))
(50 -64 -39 127 -126 -94 14 103 -58 -47 -124 98 15 107 -45 34)
; Base64
user=> (digest/digest-base64 "MD5" "clojure")
"MsDZf4KiDmfG0YRiD2vTIg=="
; HMAC
user=> (digest/hmac-sha-256 "secret" "message")
"8b5f48702995c1598c573db1e21866a9b825d4a794d169d7060a03605796360b"

Installation

deps.edn

net.clojars.savya/digest {:mvn/version "1.5.1"}

lein

[net.clojars.savya/digest "1.5.1"]

Dev

Run lein test to run the test suite.

Run bb dev/gen.clj after changing the generated static digest convenience functions.

License

Copyright© 2017 Miki Tebeka miki.tebeka@gmail.com

Maintenance fork Copyright© 2026 Savyasachi. Original: https://github.com/clj-commons/digest

Distributed under the Eclipse Public License (same as Clojure).

Snail image in tests is public domain by Miki Tebeka

Can you improve this documentation? These fine people already did:
Miki Tebeka, Savyasachi, Michiel Borkent, Erik Assum, Lauri Oherd & Dave Yarwood
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close