Created
October 20, 2011 19:16
-
-
Save eliasson/1302024 to your computer and use it in GitHub Desktop.
Clojure md5 digest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found this by googling, you need to 0-pad the result at the head to get exactly 32 chars results