Why can't I call .update on a MessageDigest instance

when i run this from repl:

(def md (MessageDigest/getInstance "SHA-1"))
(. md update (into-array [(byte 1)  (byte 2)  (byte 3)]))

I get:

No matching method found: update for class java.security.MessageDigest$Delegate

The Java 6 docs for MessageDigest show:

update(byte[] input) 
      Updates the digest using the specified array of bytes.

and the class (class (into-array [(byte 1) (byte 2) (byte 3)]))is equal [Ljava.lang.Byte;

Am I missing something in the update definition?
Without creating a class, I think I?
Without passing this type, I think I?

+3
source share
2 answers

Try:

(. md update (into-array Byte/TYPE [(byte 1) (byte 2) (byte 3)]))
+2
source

Because you are calling an update (Byte []) that is not defined in MessageDigest. You need to convert it to a primitive array.

You can do something like this,

 (defn updateBytes [#^MessageDigest md, #^bytes data] 
      (.update md data)) 
+3
source

Source: https://habr.com/ru/post/1745677/


All Articles