You should get a new, separate instance for every digest you would like to 
generate "concurrently". Nothing, i.e. no mutable state, is shared between 
different MessageDigest instances in the subsequent digesting/secure-hashing.

The .reset is only used if you want to give up you current effort without 
generating the final digest with .digest as the latter already does the reset 
implicitly. After the reset you can reuse that same MessageDigest object for a 
new digest.

You can optionally .clone a MessageDigest object is you want to have a final 
digest value for a partial byte-list. For example, if you want the digest for 
both "a" and "abc", you could take a new MessageDigest object, .update it for 
"a"'s bytes, .clone that MessageDigest, use one copy to generate the final 
.digest for "a", and use the other copy to add the digest of "bc"'s bytes and 
.digest that.

Ough… hope that's clear...

-FS.


On Mar 4, 2013, at 12:15 PM, Aaron Cohen <[email protected]> wrote:

> I'm not familiar with the class, but it seems that MessageDigest/getInstance 
> might retrieve some shared instance that could theoretically need to be 
> reset, no?
> 
> 
> On Mon, Mar 4, 2013 at 2:43 PM, Frank Siebenlist <[email protected]> 
> wrote:
> That should work.
> 
> No need for .reset though as the initially constructed MessageDigest is 
> already in its initial state.
> 
> Be careful with .digest as it implicitly resets the MessageDigest, and 
> calling it a second time gives you the digest of the initial state which is 
> not what you want.
> 
> (all that "incidental complexity" is why I started to write that functional 
> interface ;-) )
> 
> -FS.
> 
> 
> On Mar 4, 2013, at 11:32 AM, Aaron Cohen <[email protected]> wrote:
> 
> > Ah darn, thanks for the catch. The following is uglier but should work I 
> > guess. :\
> >
> > digest (.digest
> >                (doto (java.security.MessageDigest/getInstance "sha1")
> >                      .reset
> >                      (.update nonce-bytes)
> >                      (.update created-bytes)
> >                      (.update secret-bytes)))
> >
> >
> > On Mon, Mar 4, 2013 at 2:25 PM, Frank Siebenlist 
> > <[email protected]> wrote:
> > > digest (-> (java.security.MessageDigest/getInstance "sha1")
> > >                     .reset
> > >                     (.update nonce-bytes)
> > >                     (.update create-bytes)
> > >                     (.update secret-bytes)
> > >                     .digest)
> >
> >
> > There may be an issue with this snippet of code as ".update" does not 
> > return anything… i.e. nil.
> >
> > -FS.
> >
> >
> >
> > On Mar 4, 2013, at 11:06 AM, larry google groups 
> > <[email protected]> wrote:
> >
> > >>
> > >> ;; Should "UsernameToken Username" really be unquoted in the following 
> > >> line?
> > >> ;; All the other variable names are quoted
> > >
> > > Apparently, yes. The developer at Omniture reviewed it and said my
> > > only problem was the way the passwordDigest was created.
> > >
> > >
> > >
> > > On Mar 4, 2:02 pm, Aaron Cohen <[email protected]> wrote:
> > >> I think you should try to avoid the string concatenation games. I'm not
> > >> sure what your current code is, but I suspect you're still ending up with
> > >> array toString's slipping in.
> > >>
> > >> How about the following?
> > >>
> > >> On Mon, Mar 4, 2013 at 1:31 PM, larry google groups <
> > >>
> > >> [email protected]> wrote:
> > >>> So, right now I am using this code:
> > >>
> > >>>  (let [username (get-in @um/interactions [:omniture-api-
> > >>> credentials :username])
> > >>>   secret (get-in @um/interactions [:omniture-api-credentials :shared-
> > >>> secret])
> > >>>   nonce (DigestUtils/md5Hex (str (math/round (* (rand 1 ) 1000000))))
> > >>>   nonce-encoded-base64 (Base64/encodeBase64 (.getBytes nonce))
> > >>>   date-formatter (new SimpleDateFormat "yyyy-MM-dd'T'HH:mm:ss")
> > >>>   formatter gmt-timezone)
> > >>>   created (.format date-formatter (new Date))
> > >>
> > >>    nonce-bytes (.getBytes nonce)
> > >>    created-bytes (.getBytes created)
> > >>    secret-bytes (.getBytes secret)
> > >>    digest (-> (java.security.MessageDigest/getInstance "sha1")
> > >>                     .reset
> > >>                     (.update nonce-bytes)
> > >>                     (.update create-bytes)
> > >>                     (.update secret-bytes)
> > >>                     .digest)
> > >>     digest-base64 (Base64/encodeBase64 digest)
> > >>
> > >> ;; Should "UsernameToken Username" really be unquoted in the following 
> > >> line?
> > >> ;; All the other variable names are quoted
> > >>     header (apply str " UsernameToken Username=\""  username
> > >>
> > >> ;; You may want digest-base64 here?
> > >>                               "\"PasswordDigest=\"" digest
> > >>
> > >>                               "\" Nonce=\"" nonce-encoded-base64
> > >>                               "\"Created=\"" created "\"")]
> > >>              header)
> > >
> > > --
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to [email protected]
> > > Note that posts from new members are moderated - please be patient with 
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > 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 [email protected].
> > > 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 [email protected]
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > [email protected]
> > 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 [email protected].
> > 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 [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to