argon2 vs bcrypt vs bcrypt-nodejs vs bcryptjs
パスワードハッシュライブラリ
argon2bcryptbcrypt-nodejsbcryptjs類似パッケージ:

パスワードハッシュライブラリ

パスワードハッシュライブラリは、ユーザーのパスワードを安全に保存するために使用されるツールです。これらのライブラリは、パスワードをハッシュ化し、データベースに保存する際のセキュリティを強化します。安全なハッシュ化は、データ漏洩が発生した場合でも、ユーザーのパスワードを保護するために重要です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
argon202,1511.03 MB510ヶ月前MIT
bcrypt07,8011.11 MB341年前MIT
bcrypt-nodejs0---13年前-
bcryptjs03,794112 kB27ヶ月前BSD-3-Clause

機能比較: argon2 vs bcrypt vs bcrypt-nodejs vs bcryptjs

セキュリティ

  • argon2:

    Argon2は、パスワードハッシュのセキュリティを最大化するために設計されています。メモリ、時間、並列度を調整でき、これにより攻撃者のブルートフォース攻撃を防ぎます。特に、Argon2idは、時間とメモリの両方を考慮した設計で、非常に安全です。

  • bcrypt:

    Bcryptは、ハッシュ化の際にソルトを自動的に生成し、パスワードの安全性を向上させます。計算コストを調整することで、ハッシュ化の難易度を上げることができ、セキュリティを強化します。

  • bcrypt-nodejs:

    Bcrypt-nodejsは、C++の依存関係がないため、Node.js環境で簡単に使用できますが、パフォーマンスは他の実装に比べて劣ります。

  • bcryptjs:

    Bcryptjsは、ブラウザ環境でも動作するため、クライアントサイドでのパスワードハッシュ化が可能です。これにより、ユーザーのパスワードをサーバーに送信する前にハッシュ化することができ、セキュリティを向上させます。

パフォーマンス

  • argon2:

    Argon2は、メモリ使用量を調整できるため、ハードウェアの能力に応じて最適化できます。これにより、特に高負荷の環境でも良好なパフォーマンスを発揮します。

  • bcrypt:

    Bcryptは、ハッシュ化に一定の時間がかかりますが、計算コストを調整することで、パフォーマンスとセキュリティのバランスを取ることができます。

  • bcrypt-nodejs:

    Bcrypt-nodejsは、JavaScriptで実装されているため、C++の実装に比べてパフォーマンスが劣りますが、環境に依存せずに動作します。

  • bcryptjs:

    Bcryptjsは、ブラウザ環境での使用に最適化されており、軽量なアプリケーションでのパフォーマンスを重視しています。

互換性

  • argon2:

    Argon2は、最新のアルゴリズムであるため、古いシステムとの互換性がない場合がありますが、セキュリティが最優先の場合に選択するのが良いでしょう。

  • bcrypt:

    Bcryptは、広く使用されているため、多くのプロジェクトやライブラリとの互換性があります。特に、既存のシステムに統合する際に適しています。

  • bcrypt-nodejs:

    Bcrypt-nodejsは、Node.js環境で動作するため、特にNode.jsプロジェクトに適しています。

  • bcryptjs:

    Bcryptjsは、Node.jsとブラウザの両方で動作するため、クロスプラットフォームのアプリケーションに適しています。

導入の容易さ

  • argon2:

    Argon2は、設定がやや複雑ですが、セキュリティを重視するプロジェクトにおいては導入する価値があります。

  • bcrypt:

    Bcryptは、シンプルなAPIを提供しており、導入が容易です。多くのドキュメントやサポートが存在します。

  • bcrypt-nodejs:

    Bcrypt-nodejsは、C++の依存関係がないため、Node.js環境での導入が簡単です。

  • bcryptjs:

    Bcryptjsは、ブラウザ環境でも使用できるため、特にクライアントサイドでの導入が容易です。

メンテナンス

  • argon2:

    Argon2は、最新のアルゴリズムであり、活発にメンテナンスされています。セキュリティの観点からも、定期的な更新が行われています。

  • bcrypt:

    Bcryptは、広く使用されているため、コミュニティによるサポートが充実しており、メンテナンスも行き届いています。

  • bcrypt-nodejs:

    Bcrypt-nodejsは、C++の依存関係がないため、メンテナンスが容易ですが、パフォーマンスは他の実装に劣ります。

  • bcryptjs:

    Bcryptjsは、軽量であり、ブラウザ環境でも動作するため、メンテナンスが容易です。

選び方: argon2 vs bcrypt vs bcrypt-nodejs vs bcryptjs

  • argon2:

    Argon2は、最新のパスワードハッシュアルゴリズムであり、特にセキュリティが重視されるアプリケーションに適しています。メモリ使用量や計算負荷を調整できるため、攻撃者によるブルートフォース攻撃に対して強い耐性を持っています。

  • bcrypt:

    Bcryptは、広く使用されているパスワードハッシュライブラリで、セキュリティとパフォーマンスのバランスが取れています。特に、既存のプロジェクトやライブラリとの互換性が重要な場合に選択するのが良いでしょう。

  • bcrypt-nodejs:

    Bcrypt-nodejsは、Node.js環境で動作するbcryptの純粋なJavaScript実装です。C++の依存関係がないため、環境に依存せずに動作しますが、パフォーマンスはbcryptに比べて劣ります。

  • bcryptjs:

    Bcryptjsは、bcryptのJavaScript実装で、特にブラウザ環境での使用に適しています。Node.jsとブラウザの両方で動作し、簡単に導入できるため、軽量なアプリケーションに適しています。

argon2 のREADME

node-argon2

Financial contributors on Open Collective Build status NPM package

Bindings to the reference Argon2 implementation.

Usage

It's possible to hash using either Argon2i, Argon2d or Argon2id (default), and verify if a password matches a hash.

To hash a password:

const argon2 = require('argon2');

try {
  const hash = await argon2.hash("password");
} catch (err) {
  //...
}

To see how you can modify the output (hash length, encoding) and parameters (time cost, memory cost and parallelism), read the wiki

To verify a password:

try {
  if (await argon2.verify("<big long hash>", "password")) {
    // password match
  } else {
    // password did not match
  }
} catch (err) {
  // internal failure
}

Migrating from another hash function

See this article on the wiki for steps on how to migrate your existing code to Argon2. It's easy!

TypeScript usage

A TypeScript type declaration file is published with this module. If you are using TypeScript 2.0.0 or later, that means you do not need to install any additional typings in order to get access to the strongly typed interface. Simply use the library as mentioned above.

import * as argon2 from "argon2";

const hash = await argon2.hash(..);

Prebuilt binaries

node-argon2 provides prebuilt binaries from v0.26.0 onwards. They are built every release using GitHub Actions.

The current prebuilt binaries are built and tested with the following systems:

  • Ubuntu 22.04 (x86-64; ARM64 from v0.28.2; ARMv7 from v0.43.0)
  • MacOS 13 (x86-64)
  • MacOS 14 (ARM64 from v0.29.0)
  • Windows Server 2022 (x86-64)
  • Alpine Linux 3.18 (x86-64 from v0.28.1; ARM64 from v0.28.2; ARMv7 from v0.43.0)
  • FreeBSD 14 (x86-64 from v0.29.1; ARM64 from v0.44.0)

Binaries should also work for any version more recent than the ones listed above. For example, the binary for Ubuntu 20.04 also works on Ubuntu 22.04, or any other Linux system that ships a newer version of glibc; the binary for MacOS 11 also works on MacOS 12. If your platform is below the above requirements, you can follow the Before installing section below to manually compile from source. It is also always recommended to build from source to ensure consistency of the compiled module.

Before installing

You can skip this section if the prebuilt binaries work for you.

You MUST have a node-gyp global install before proceeding with the install, along with GCC >= 5 / Clang >= 3.3. On Windows, you must compile under Visual Studio 2015 or newer.

node-argon2 works only and is tested against Node >=18.0.0.

OSX

To install GCC >= 5 on OSX, use homebrew:

$ brew install gcc

Once you've got GCC installed and ready to run, you then need to install node-gyp, you must do this globally:

$ npm install -g node-gyp

Finally, once node-gyp is installed and ready to go, you can install this library, specifying the GCC or Clang binary to use:

$ CXX=g++-12 npm install argon2

NOTE: If your GCC or Clang binary is named something different than g++-12, you'll need to specify that in the command.

FAQ

How do I manually rebuild the binaries?
$ npx @mapbox/node-pre-gyp rebuild -C ./node_modules/argon2

Run @mapbox/node-pre-gyp instead of node-gyp because node-argon2's binding.gyp file relies on variables from @mapbox/node-pre-gyp.

You can omit npx @mapbox and use just node-pre-gyp if you have a global installation of @mapbox/node-pre-gyp, otherwise prefixing npx will use the local one in ./node_modules/.bin

How do I skip installing prebuilt binaries and manually compile from source?

You can do either of the two methods below:

  1. Force build from source on install.
$ npm install argon2 --build-from-source
  1. Ignore node-argon2 install script and build manually.
$ npm install argon2 --ignore-scripts
$ npx node-gyp rebuild -C ./node_modules/argon2
I installed Node as a snap, and I can't install node-argon2.

This seems to be an issue related to snap (see #345 (comment)). Installing Node with another package manager, such as asdf or nvm, is a possible workaround.

Contributors

Code contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

Work licensed under the MIT License. Please check P-H-C/phc-winner-argon2 for license over Argon2 and the reference implementation.