Created
March 5, 2012 13:50
-
-
Save jramb/1978394 to your computer and use it in GitHub Desktop.
Password hashing in Clojure
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 hash-password [password salt] | |
(assert (> (count salt) 10)) ;would like to have >64 bit of salt | |
(assert (> (count password) 6)) ;come on, how low can we go? | |
(let [md (java.security.MessageDigest/getInstance "SHA-512") | |
encoder (sun.misc.BASE64Encoder.)] | |
(.update md (.getBytes salt "UTF-8")) ;assume text salt | |
(.encode encoder | |
(loop [mangle (.getBytes password "UTF-8") | |
passes 1e5] ; paranoid, but are we paranoid enough? | |
(if (= 0 passes) | |
mangle | |
(recur (.digest md mangle) (dec passes))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment