Skip to content

Instantly share code, notes, and snippets.

@eliasson
Created October 20, 2011 19:16
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eliasson/1302024 to your computer and use it in GitHub Desktop.
Save eliasson/1302024 to your computer and use it in GitHub Desktop.
Clojure md5 digest
(defn md5
"Generate a md5 checksum for the given string"
[token]
(let [hash-bytes
(doto (java.security.MessageDigest/getInstance "MD5")
(.reset)
(.update (.getBytes token)))]
(.toString
(new java.math.BigInteger 1 (.digest hash-bytes)) ; Positive and the size of the number
16))) ; Use base16 i.e. hex
@skuro
Copy link

skuro commented Sep 23, 2012

Found this by googling, you need to 0-pad the result at the head to get exactly 32 chars results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment