企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## guava中的hash函数 代码测试:(`guava`里约14种`hash`算法,其中`md5`,`sha256`,`sha1`等比较常用) 可根据实际应用场景选择不同的hash算法来得到hash值。 ~~~ public static void main(String[] args) { String str = "中国"; Charset utf8 = Charsets.UTF_8; String v1 = Hashing.md5().hashString(str,utf8).toString(); System.out.println("md5="+v1+",len="+v1.length()); String v2 = Hashing.sha256().hashString(str,utf8).toString(); System.out.println("sha256="+v2+",len="+v2.length()); String v3 = Hashing.sha384().hashString(str,utf8).toString(); System.out.println("sha384="+v3+",len="+v3.length()); String v4 = Hashing.sha512().hashString(str,utf8).toString(); System.out.println("sha512="+v4+",len="+v4.length()); String v5 = Hashing.sha1().hashString(str,utf8).toString(); System.out.println("sha1="+v5+",len="+v5.length()); String v6 = Hashing.adler32().hashString(str,utf8).toString(); System.out.println("adler32="+v6+",len="+v6.length()); String v7 = Hashing.crc32().hashString(str,utf8).toString(); System.out.println("crc32="+v7+",len="+v7.length()); String v8 = Hashing.crc32c().hashString(str,utf8).toString(); System.out.println("crc32c="+v8+",len="+v8.length()); String v9 = Hashing.farmHashFingerprint64().hashString(str,utf8).toString(); System.out.println("farmHashFingerprint64="+v9+",len="+v9.length()); String v10 = Hashing.fingerprint2011().hashString(str,utf8).toString(); System.out.println("fingerprint2011="+v10+",len="+v10.length()); String v11 = Hashing.goodFastHash(32).hashString(str,utf8).toString(); System.out.println("goodFastHash="+v11+",len="+v11.length()); String v12 = Hashing.murmur3_32_fixed().hashString(str,utf8).toString(); System.out.println("murmur3_32_fixed="+v12+",len="+v12.length()); String v13 = Hashing.murmur3_128().hashString(str,utf8).toString(); System.out.println("murmur3_128="+v13+",len="+v13.length()); String v14 = Hashing.sipHash24().hashString(str,utf8).toString(); System.out.println("sipHash24="+v14+",len="+v14.length()); } ~~~ 输出如下: ``` md5=c13dceabcb143acd6c9298265d618a9f,len=32 sha256=f0e9521611bb290d7b09b8cd14a63c3fe7cbf9a2f4e0090d8238d22403d35182,len=64 sha384=ebe1c5966f14a75396a6b2b31395fc3bcc01d3d3c43b7d135e72c8e3d9bbe6461d8aeac37c208e1312e2f278074d7e29,len=96 sha512=6a169e7d5b7526651086d0d37d6e7686c7e75ff7039d063ad100aefab1057a4c1db1f1e5d088c9585db1d7531a461ab3f4490cc63809c08cc074574b3fff759a,len=128 sha1=101806f57c322fb403a9788c4c24b79650d02e77,len=40 adler32=87044c10,len=8 crc32=91f4ed2b,len=8 crc32c=b4fa9f6e,len=8 farmHashFingerprint64=8700addaa89b49e4,len=16 fingerprint2011=c4e96332322ae95e,len=16 goodFastHash=ea254d70,len=8 murmur3_32_fixed=8d8e49b4,len=8 murmur3_128=2eb5789f40b874a589f000803b6152fd,len=32 sipHash24=e6ad2033988a7f9b,len=16 ```