bcrypt-nodejs vs argon2 vs bcrypt vs bcryptjs
密码哈希库
bcrypt-nodejsargon2bcryptbcryptjs类似的npm包:

密码哈希库

密码哈希库用于安全地存储用户密码,通过将密码转换为不可逆的哈希值来保护用户的敏感信息。这些库实现了不同的哈希算法和安全特性,以确保密码存储的安全性。选择合适的哈希库对于防止密码泄露和提高应用程序的安全性至关重要。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
bcrypt-nodejs65,782---13 年前-
argon202,182959 kB71 个月前MIT
bcrypt07,8021.11 MB381 年前MIT
bcryptjs03,799112 kB510 个月前BSD-3-Clause

功能对比: bcrypt-nodejs vs argon2 vs bcrypt vs bcryptjs

安全性

  • bcrypt-nodejs:

    Bcrypt-nodejs 是 Bcrypt 的 JavaScript 实现,虽然安全性与 Bcrypt 相似,但由于是纯 JavaScript 实现,可能在性能上有所欠缺。

  • argon2:

    Argon2 提供了强大的安全性,支持内存和时间成本的配置,能够有效抵御暴力破解和 GPU 攻击。它是当前推荐的密码哈希算法,具有灵活的参数设置,允许开发者根据需求调整安全性。

  • bcrypt:

    Bcrypt 是一种经过验证的密码哈希算法,具有自适应性,随着计算能力的提高,可以增加哈希的复杂度。它使用盐值来防止彩虹表攻击,确保每个密码的哈希都是唯一的。

  • bcryptjs:

    Bcryptjs 是一个轻量级的 Bcrypt 实现,适合在浏览器和 Node.js 中使用,提供了良好的安全性,但在性能上可能不如原生实现。

性能

  • bcrypt-nodejs:

    Bcrypt-nodejs 的性能较低,主要是因为它是纯 JavaScript 实现,适合对性能要求不高的应用。

  • argon2:

    Argon2 在性能上表现出色,尤其是在内存使用方面,允许开发者根据需求调整内存和时间成本,以优化性能和安全性之间的平衡。

  • bcrypt:

    Bcrypt 在性能上表现良好,但随着哈希复杂度的增加,处理速度会变慢,适合中小型应用。

  • bcryptjs:

    Bcryptjs 的性能与 bcrypt-nodejs 类似,适合轻量级应用,但在处理大量哈希时可能会显得缓慢。

易用性

  • bcrypt-nodejs:

    Bcrypt-nodejs 的 API 与 Bcrypt 类似,但由于是 JavaScript 实现,可能在某些情况下不如其他实现直观。

  • argon2:

    Argon2 的使用相对简单,提供了清晰的 API 和文档,适合开发者快速上手。

  • bcrypt:

    Bcrypt 的 API 简洁明了,易于集成到现有项目中,社区支持良好,文档丰富。

  • bcryptjs:

    Bcryptjs 提供了简单的 API,易于使用,适合需要在浏览器中使用的场景。

社区支持

  • bcrypt-nodejs:

    Bcrypt-nodejs 的社区相对较小,但由于其与 Bcrypt 的兼容性,仍然可以找到一些支持和文档。

  • argon2:

    Argon2 拥有活跃的社区和良好的文档支持,随着安全需求的提高,越来越多的项目开始采用它。

  • bcrypt:

    Bcrypt 是最流行的密码哈希算法之一,拥有广泛的社区支持和大量的使用案例,文档和示例丰富。

  • bcryptjs:

    Bcryptjs 也有一定的社区支持,适合需要轻量级解决方案的开发者。

跨平台支持

  • bcrypt-nodejs:

    Bcrypt-nodejs 是纯 JavaScript 实现,适合在 Node.js 和浏览器中使用,具有良好的跨平台能力。

  • argon2:

    Argon2 在多个平台上均可用,支持多种语言的实现,适合需要跨平台的应用。

  • bcrypt:

    Bcrypt 在多种语言中都有实现,适合需要跨平台支持的项目。

  • bcryptjs:

    Bcryptjs 也支持在浏览器和 Node.js 中使用,适合需要跨平台的轻量级应用。

如何选择: bcrypt-nodejs vs argon2 vs bcrypt vs bcryptjs

  • bcrypt-nodejs:

    选择 Bcrypt-nodejs 如果你需要一个纯 JavaScript 实现的 Bcrypt 库,适合在 Node.js 环境中使用,但请注意它的性能可能不如其他实现。

  • argon2:

    选择 Argon2 如果你需要一个现代的、内存硬化的哈希算法,适合对抗 GPU 攻击,并且希望在安全性和性能之间找到平衡。它是密码哈希竞赛的获胜者,具有灵活的参数配置。

  • bcrypt:

    选择 Bcrypt 如果你需要一个广泛使用且经过验证的哈希算法,适合大多数应用场景。它提供了良好的安全性和相对较快的性能,适合中小型应用。

  • bcryptjs:

    选择 Bcryptjs 如果你需要一个轻量级的、纯 JavaScript 实现的 Bcrypt 库,适合在浏览器和 Node.js 中使用,且不依赖于 C++ 扩展,便于跨平台使用。

bcrypt-nodejs的README

bcrypt-nodejs

Warning : A change was made in v0.0.3 to allow encoding of UTF-8 encoded strings. This causes strings encoded in v0.0.2 or earlier to not work in v0.0.3 anymore.

Native JS implementation of BCrypt for Node. Has the same functionality as node.bcrypt.js expect for a few tiny differences. Mainly, it doesn't let you set the seed length for creating the random byte array.

I created this version due to a small problem I faced with node.bcrypt.js. Basically, to deploy one of my apps which uses node.bcrypt.js on a winx64 platform, I have to force the user to download about 1.6gb of sdks, buildtools and other requirements of which some fail to install ! Microsoft :(

This code is based on javascript-bcrypt and uses [crypto] (http://nodejs.org/api/crypto.html) to create random byte arrays.

Basic usage:

Synchronous

var hash = bcrypt.hashSync("bacon");

bcrypt.compareSync("bacon", hash); // true
bcrypt.compareSync("veggies", hash); // false

Asynchronous

bcrypt.hash("bacon", null, null, function(err, hash) {
	// Store hash in your password DB.
});

// Load hash from your password DB.
bcrypt.compare("bacon", hash, function(err, res) {
    // res == true
});
bcrypt.compare("veggies", hash, function(err, res) {
    // res = false
});

In the above examples, the salt is automatically generated and attached to the hash. Though you can use your custom salt and there is no need for salts to be persisted as it will always be included in the final hash result and can be retrieved.

API

  • genSaltSync(rounds)
    • rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
  • genSalt(rounds, callback)
    • rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
    • callback - [REQUIRED] - a callback to be fired once the salt has been generated.
      • error - First parameter to the callback detailing any errors.
      • result - Second parameter to the callback providing the generated salt.
  • hashSync(data, salt)
    • data - [REQUIRED] - the data to be encrypted.
    • salt - [REQUIRED] - the salt to be used in encryption.
  • hash(data, salt, progress, cb)
    • data - [REQUIRED] - the data to be encrypted.
    • salt - [REQUIRED] - the salt to be used to hash the password.
    • progress - a callback to be called during the hash calculation to signify progress
    • callback - [REQUIRED] - a callback to be fired once the data has been encrypted.
      • error - First parameter to the callback detailing any errors.
      • result - Second parameter to the callback providing the encrypted form.
  • compareSync(data, encrypted)
    • data - [REQUIRED] - data to compare.
    • encrypted - [REQUIRED] - data to be compared to.
  • compare(data, encrypted, cb)
    • data - [REQUIRED] - data to compare.
    • encrypted - [REQUIRED] - data to be compared to.
    • callback - [REQUIRED] - a callback to be fired once the data has been compared.
      • error - First parameter to the callback detailing any errors.
      • result - Second parameter to the callback providing whether the data and encrypted forms match [true | false].
  • getRounds(encrypted) - return the number of rounds used to encrypt a given hash
    • encrypted - [REQUIRED] - hash from which the number of rounds used should be extracted.

Contributors

Credits

I heavily reused code from javascript-bcrypt. Though "Clipperz Javascript Crypto Library" was removed and its functionality replaced with "crypto".