larry google groups <lawrencecloj...@gmail.com> writes:

> Hmm, interesting. I had assumed that I wanted a string run through
> SHA1, so I created the string, then called getBytes on it to feed it
> to SHA1:
>
>  digest-as-string (apply str nonce created secret)
>  digest (.digest (java.security.MessageDigest/getInstance "sha1")
> (.getBytes digest-as-string))
>

(defn sha1[^bytes b]
  (.digest (doto (java.security.MessageDigest/getInstance "SHA-1")
             (.reset)
             (.update b))))

(defn as-hex [^bytes v]
  (clojure.string/lower-case
   (javax.xml.bind.DatatypeConverter/printHexBinary v)))

(defn sha1-hex [^String v]
  (-> (.getBytes v)
      (sha1)
      (as-hex)))

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to