WebAssembly implementation of bcrypt. This module began life as a quasi-fork of the bcrypt module. Currently, only the synchronous APIs are available.
'use strict';
const Bcrypt = require('bcrypt.wasm');
const data = 'password';
const salt = Bcrypt.genSaltSync();
const hash = Bcrypt.hashSync(data, salt);
Bcrypt.compareSync(data, hash); // equals true
Bcrypt.compareSync(data + 'x', hash); // equals false
bcrypt.wasm
exports the following methods.
- Arguments
data
(string) - Cleartext data to compare against an encrypted hash.hash
(string) - An encrypted hash to compare against cleartext input.
- Returns
match
(boolean) -true
if the comparison succeeds, andfalse
otherwise.
- Arguments
rounds
(number) - The cost of generating a salt. Optional. Defaults to10
.
- Returns
salt
(string) - The generated salt.
- Arguments
hash
(string) - An encrypted hash.
- Returns
rounds
(number) - The number of rounds used to encrypthash
.
- Arguments
data
(string) - Cleartext data to encrypt.salt
(number or string) - The salt used to hashdata
. Ifsalt
is a number, it is passed togenSaltSync()
to generate a salt string.
- Returns
hash
(string) - The encrypted hash ofdata
usingsalt
.