0.1.0 • Published 8 years ago
bcrypt.wasm v0.1.0
bcrypt.wasm
WebAssembly implementation of bcrypt. This module began life as a quasi-fork of the bcrypt module. Currently, only the synchronous APIs are available.
Basic Usage
'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 falseAPI
bcrypt.wasm exports the following methods.
compareSync(data, hash)
- Arguments
data(string) - Cleartext data to compare against an encrypted hash.hash(string) - An encrypted hash to compare against cleartext input.
- Returns
match(boolean) -trueif the comparison succeeds, andfalseotherwise.
genSaltSync(rounds)
- Arguments
rounds(number) - The cost of generating a salt. Optional. Defaults to10.
- Returns
salt(string) - The generated salt.
getRounds(hash)
- Arguments
hash(string) - An encrypted hash.
- Returns
rounds(number) - The number of rounds used to encrypthash.
hashSync(data, salt)
- Arguments
data(string) - Cleartext data to encrypt.salt(number or string) - The salt used to hashdata. Ifsaltis a number, it is passed togenSaltSync()to generate a salt string.
- Returns
hash(string) - The encrypted hash ofdatausingsalt.
0.1.0
8 years ago