(-> "Hello, World!" .getBytes create-hash ...)

Will get you the hash of the string encoded to bytes using *some random
encoding*. (Whatever the platform you're currently running on defaults to.)

You should explicitly choose an encoding and stick to it. I'd suggest UTF-8
since that can encode all the code points that might show up in a Java
String.

(-> "Hello, World!" (.getBytes "UTF-8") create-hash java.math.BigInteger.)

// Ben


On Sat, Mar 1, 2014 at 7:49 PM, Zach Oakes <zsoa...@gmail.com> wrote:

> You can use java.security.MessageDigest. For example:
>
> (defn create-hash
>   [data-barray]
>   (.digest (java.security.MessageDigest/getInstance "SHA1") data-barray))
>
> It takes and returns a byte array, but converting from/to a string is
> fairly straight-forward:
>
> (->> "Hello, World!"
>      .getBytes
>      create-hash
>      java.math.BigInteger.
>      (format "%x")
>      println)
>
> On Saturday, March 1, 2014 11:26:29 AM UTC-5, action wrote:
>
>> do like this:
>> (ns clojurewerkz.support.hashing
>>   (:require [clojurewerkz.support.internal :as i])
>>   (:import [com.google.common.hash Hashing HashFunction HashCode]))
>> but:
>> FileNotFoundException Could not locate clojurewerkz/support__init.class
>> or cloju
>> rewerkz/support.clj on classpath:   clojure.lang.RT.load (RT.java:443)
>> how to set the dependencies, or other solution?
>>
>> Think you
>>
>>
>>  --
> 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.
>

-- 
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