JavaScript相当于Guava的HashCode?

问题描述 投票:0回答:2

在Java中,我使用Google Guava获取hashCode:

HashFunction hashFunction = Hashing.md5();
Hasher hasher = hashFunction.newHasher();
hasher.putLong(arg);
HashCode hashCode = hasher.hash();
long asLong = hashCode.asLong();

在JavaScript中是否有相同的功能?

javascript java node.js guava hashcode
2个回答
1
投票

显然对于MD5哈希,然后在Javascript中没有NATIVE等价物。 MD5很弱,已经被SubtleCrypto库弃用了。 SHA1仍然受支持,但最近也被破解,所以我会使用SHA-2(SHA-256,SHA-384和SHA-512是同一算法的不同大小,这可能令人困惑 - 它们都是SHA-2)用于任何与安全相关的项目。如果您只想将此作为确定一个数据块与另一个数据块不同的快速方法,那么SHA-1就足够了。

这是Mozilla对SubtleCrypto.digest方法的写法:https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest


0
投票

Google Guava是库的集合,即核心语言的打包扩展。在JavaScript和大多数其他语言中都有MD5和其他散列函数的自定义实现。有关Javascript中的示例:http://pajhome.org.uk/crypt/md5/md5.html

所以你只需要包含它们就可以在Javascript中使用它们。

© www.soinside.com 2019 - 2024. All rights reserved.