代码之家  ›  专栏  ›  技术社区  ›  Arthur Ulfeldt

为什么我不能在MessageDigest实例上调用.update

  •  3
  • Arthur Ulfeldt  · 技术社区  · 14 年前

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

    我得到:

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

    MessageDigest的Java 6文档显示:

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

    以及 (class (into-array [(byte 1) (byte 2) (byte 3)])) [Ljava.lang.Byte;

    我在更新的定义中遗漏了什么吗?
    不是我想的那个班级吗?
    不是我想的那种类型吗?

    2 回复  |  直到 14 年前
        1
  •  2
  •   G__    14 年前

    尝试:

    (. md update (into-array Byte/TYPE [(byte 1) (byte 2) (byte 3)]))
    
        2
  •  3
  •   ZZ Coder    14 年前

    因为您正在调用MessageDigest中未定义的update(Byte[])。你需要把它转换成基本数组。

    你可以这样做,

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