# argon2

> An Argon2 library for Node

Latest version **0.45.1** (published 2026-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install argon2
pnpm add argon2
yarn add argon2
bun add argon2
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.45.1 |
| Published | 2026-07-21 |
| First published | 2015-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.17.0 |
| Dependencies | 4 |
| Unpacked size | 936.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2184 |
| Author | Ranieri Althoff |
| Maintainers | ranisalt |
| Keywords | argon2, crypto, encryption, hashing, password |

## Links

- npm: https://www.npmjs.com/package/argon2
- Repository: https://github.com/ranisalt/node-argon2
- Homepage: https://github.com/ranisalt/node-argon2#readme
- Issues: https://github.com/ranisalt/node-argon2/issues
- npm.io page: https://npm.io/package/argon2

## Dependencies (4)

- [cross-env](https://npm.io/package/cross-env.md) ^10.1.0
- [@phc/format](https://npm.io/package/@phc/format.md) ^1.0.0
- [node-addon-api](https://npm.io/package/node-addon-api.md) ^8.9.0
- [node-gyp-build](https://npm.io/package/node-gyp-build.md) ^4.8.4

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.45.1 (latest) — 2026-07-21
- 1.0.0-alpha.1 (next) — 2026-07-18
- 0.40.2 (true) — 2024-05-25
- 0.45.0 — 2026-07-18
- 0.44.0 — 2025-08-10
- 0.43.1 — 2025-07-14
- 0.43.0 — 2025-04-24
- 0.41.1 — 2024-08-31
- 0.41.0 — 2024-08-25
- 0.40.3 — 2024-05-25
- 0.40.1 — 2024-02-22
- 0.40.0-alpha.3 — 2024-01-10
- 0.40.0-alpha.2 — 2023-12-30
- 0.40.0-alpha.1 — 2023-12-20
- 0.31.2 — 2023-11-04
- … 69 more at https://npm.io/package/argon2/versions

## README

# node-argon2

[![Financial contributors on Open Collective][opencollective-image]][opencollective-url]
[![Build status][actions-image]][actions-url]
[![NPM package][npm-image]][npm-url]

Bindings to the reference [Argon2](https://github.com/P-H-C/phc-winner-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:

```js
const argon2 = require("argon2");

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

To verify a password:

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

> [!NOTE]
> By default, argon2.hash will generate secure hashes according to the security recommendations by the team that develops Argon2.
> **For password hashing, there is no need to modify them.**

To see how you can modify the output (hash length, encoding) and parameters
(time cost, memory cost and parallelism),
[read the wiki](https://github.com/ranisalt/node-argon2/wiki/Options)

### Comparison with the node:crypto native implementation

The native API is focused towards generic usage of the Argon2 hash function, while this package historically focused on password hashing.

Once all supported Node releases include native Argon2 and older versions are officially EOL, node-argon2 will transition into a minimal wrapper. It will offer the most developer-friendly interface, bridging users to Node's native crypto methods. This avoids duplication and ensures seamless upgrades once native support is universal.

|                                                                                                                   | node-argon2 | node:crypto argon2 |
| ----------------------------------------------------------------------------------------------------------------- | ----------- | ------------------ |
| Generate hashes                                                                                                   | ✅          | ✅                 |
| [PHC string formatting](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md)                    | ✅          | ❌                 |
| Verify PHC string                                                                                                 | ✅          | ❌                 |
| Check if re-hash is needed                                                                                        | ✅          | ❌                 |
| [Provide sensible default parameters](https://github.com/ranisalt/node-argon2/issues/469#issuecomment-3452416217) | ✅          | ❌                 |

### Migrating from another hash function

See [this article on the wiki](https://github.com/ranisalt/node-argon2/wiki/Migrating-from-another-hash-function) 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.

```ts
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](#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](#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 >=22.0.0.

### OSX

To install GCC >= 5 on OSX, use [homebrew](http://brew.sh/):

```console
$ 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:

```console
$ 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:

```console
$ 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

<details>
  <summary>How do I manually rebuild the binaries?</summary>

```bash
$ 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`

</details>

<details>
  <summary>
    How do I skip installing prebuilt binaries and manually compile from source?
  </summary>

You can do either of the two methods below:

1. Force build from source on install.

```bash
$ npm install argon2 --build-from-source
```

2. Ignore `node-argon2` install script and build manually.

```bash
$ npm install argon2 --ignore-scripts
$ npx node-gyp rebuild -C ./node_modules/argon2
```

</details>

<details>
  <summary>
    I installed Node as a <a href="https://snapcraft.io/node">snap</a>, and I can't install node-argon2.
  </summary>

This seems to be an issue related to snap (see [#345 (comment)](https://github.com/ranisalt/node-argon2/issues/345#issuecomment-1164178674)). Installing Node with another package manager, such as [asdf](https://asdf-vm.com/) or [nvm](https://github.com/nvm-sh/nvm), is a possible workaround.

</details>

## Contributors

### Code contributors

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="https://github.com/ranisalt/node-argon2/graphs/contributors"><img src="https://opencollective.com/node-argon2/contributors.svg?width=890&button=false" /></a>

### Financial contributors

Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/node-argon2/contribute)]

#### Individuals

<a href="https://opencollective.com/node-argon2"><img src="https://opencollective.com/node-argon2/individuals.svg?width=890"></a>

#### Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/node-argon2/contribute)]

<a href="https://opencollective.com/node-argon2/organization/0/website"><img src="https://opencollective.com/node-argon2/organization/0/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/1/website"><img src="https://opencollective.com/node-argon2/organization/1/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/2/website"><img src="https://opencollective.com/node-argon2/organization/2/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/3/website"><img src="https://opencollective.com/node-argon2/organization/3/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/4/website"><img src="https://opencollective.com/node-argon2/organization/4/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/5/website"><img src="https://opencollective.com/node-argon2/organization/5/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/6/website"><img src="https://opencollective.com/node-argon2/organization/6/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/7/website"><img src="https://opencollective.com/node-argon2/organization/7/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/8/website"><img src="https://opencollective.com/node-argon2/organization/8/avatar.svg"></a>
<a href="https://opencollective.com/node-argon2/organization/9/website"><img src="https://opencollective.com/node-argon2/organization/9/avatar.svg"></a>

## License

Work licensed under the [MIT License](LICENSE). Please check
[P-H-C/phc-winner-argon2](https://github.com/P-H-C/phc-winner-argon2) for
license over Argon2 and the reference implementation.

[opencollective-image]: https://img.shields.io/opencollective/all/node-argon2.svg?style=flat-square
[opencollective-url]: https://opencollective.com/node-argon2
[npm-image]: https://img.shields.io/npm/v/argon2.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/argon2
[actions-image]: https://img.shields.io/github/actions/workflow/status/ranisalt/node-argon2/ci.yml?branch=master&style=flat-square
[actions-url]: https://github.com/ranisalt/node-argon2/actions

---
_Source: https://npm.io/package/argon2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
