-
-
Save w33tmaricich/36b2f29a9a4009029421 to your computer and use it in GitHub Desktop.
clj: calculate md5 hash of a given string
This file contains 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
(import 'java.security.MessageDigest | |
'java.math.BigInteger) | |
(defn md5 [s] | |
(let [algorithm (MessageDigest/getInstance "MD5") | |
size (* 2 (.getDigestLength algorithm)) | |
raw (.digest algorithm (.getBytes s)) | |
sig (.toString (BigInteger. 1 raw) 16) | |
padding (apply str (repeat (- size (count sig)) "0"))] | |
(str padding sig))) | |
; for full digest support, use clj-digest: https://github.com/tebeka/clj-digest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment