@node-rs/bcrypt
Native bcrypt password hashing for Node.js via Rust bindings, with async hash, verify, and configurable cost factor.
Official Documentation ↗v1.0. Check the official docs for the latest API surface.Installation
npm install @node-rs/bcryptMethods
No methods match this filter.
@node-rs/bcrypt is native bcrypt password hashing for node.js via rust bindings, with async hash, verify, and configurable cost factor. This page documents the core methods, installation, and common usage patterns for the current stable release.
Installation
Install @node-rs/bcrypt with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.
Core methods
The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v1.0 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.
Frequently asked questions
The faq section in the frontmatter answers the most common questions about @node-rs/bcrypt, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.
Errors
The official API reference declares the following error types:
TypeError(参数/选项类型错误时抛出,code 为 ERR_INVALID_ARG_TYPE) — official text: “Wrong argument or option types throwTypeErrorwithcode: 'ERR_INVALID_ARG_TYPE'” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts, fetched 2026-11-08T17:53:10+08:00)RangeError(类型正确但取值越界或格式非法时抛出,code 为 ERR_OUT_OF_RANGE) — official text: “values of the right type that are out of range or malformed throwRangeErrorwithcode: 'ERR_OUT_OF_RANGE'” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts, fetched 2026-11-08T17:53:10+08:00)AbortError(通过 signal 取消时 reject,name 为 AbortError、code 为 ABORT_ERR) — official text: “cancellation rejects withname: 'AbortError'andcode: 'ABORT_ERR', like Node’s AbortError.” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts, fetched 2026-11-08T17:53:10+08:00)Error(用其他 major 版本的 backend 加载包时抛出,code 为 ERR_BCRYPT_INCOMPATIBLE_BINARY) — official text: “Loading the package over a backend built for another major throwsErrorwithcode: 'ERR_BCRYPT_INCOMPATIBLE_BINARY'.” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts, fetched 2026-11-08T17:53:10+08:00)
Security
Official security statements captured from the package documentation:
- bcrypt 最多使用 72 字节密码;该默认行为对哈希与校验一致 — “Bcrypt uses at most 72 password bytes. That default is unchanged for hashing and verification, including existing database hashes.” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/README.md, fetched 2026-11-08T17:53:10+08:00)
- 可用 rejectLongPasswords: true 拒绝超过 72 字节的密码(按字节而非 JS 字符串长度判断) — “To reject longer passwords when creating a hash, explicitly set
rejectLongPasswords: true. This checks bytes, not JavaScript string length, and accepts exactly 72 bytes. Verification has no length-policy option.” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/README.md, fetched 2026-11-08T17:53:10+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T17:53:10+08:00 via WebFetch https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts.
hash→ signature from https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts; official text: “export declare function hash(password: Password, options?: HashOptions & AsyncOptions): Promise” verify→ signature from https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts; official text: “export declare function verify(password: Password, encodedHash: string | Uint8Array, options?: AsyncOptions): Promise” genSalt→ signature from https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts; official text: “export declare function genSalt(options?: SaltOptions & AsyncOptions): Promise”
FAQ
- What cost should I use?
- 12 is a common default; raise it so hashing takes about 250 ms on your hardware.
- Is bcrypt better than argon2?
- Argon2 is newer and memory-hard; bcrypt remains widely supported. Use argon2 for new systems.
- Does it ship prebuilds?
- Yes. node-rs packages include prebuilt binaries for Linux, macOS, and Windows.
Report a problem with this API docOpens a pre-filled issue on GitHub.