Skip to content

Instantly share code, notes, and snippets.

@mahata
Created July 21, 2012 02:34
Show Gist options
  • Save mahata/3154276 to your computer and use it in GitHub Desktop.
Save mahata/3154276 to your computer and use it in GitHub Desktop.
sha-512 in clojure
;; (let [md (. java.security.MessageDigest getInstance "sha-512")]
;; (. md update (.getBytes "helloworld"))
;; (let [bytes (. md digest)]
;; (reduce (fn [n x] (str n (format "%02x" x))) "" bytes)))
;; (let [md (. java.security.MessageDigest getInstance "sha-512")]
;; (. md update (.getBytes "helloworld"))
;; (let [bytes (. md digest)]
;; (reduce #(str %1 (format "%02x" %2)) "" bytes)))
(defn sha-512 [data]
(let [md (. java.security.MessageDigest getInstance "sha-512")]
(. md update (.getBytes data))
(let [bytes (. md digest)]
(reduce #(str %1 (format "%02x" %2)) "" bytes))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment