Created
July 21, 2012 02:34
-
-
Save mahata/3154276 to your computer and use it in GitHub Desktop.
sha-512 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
;; (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