bcrypt-deterministic
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,7 +0,11 @@ | ||
export declare const hash: (data: string, { salt, rounds, minor, }?: import("./methods/public/hash/types").HashProps) => Promise<string>; | ||
export declare const hashSync: (data: string, { salt, rounds, minor, }?: import("./methods/public/hashSync/types").HashProps) => Promise<string>; | ||
export declare const compare: (data: string, hash: string) => Promise<boolean>; | ||
export declare const compareSync: (data: string, hash: string) => boolean; | ||
export declare const hash: (data: string, { salt, rounds, minor }?: import("./methods/public/hash/types").HashProps) => Promise<string>; | ||
export declare const hashSync: (data: string, { salt, rounds, minor }?: import("./methods/public/hashSync/types").HashProps) => string; | ||
declare const _default: { | ||
hash: (data: string, { salt, rounds, minor, }?: import("./methods/public/hash/types").HashProps) => Promise<string>; | ||
hashSync: (data: string, { salt, rounds, minor, }?: import("./methods/public/hashSync/types").HashProps) => Promise<string>; | ||
compare: (data: string, hash: string) => Promise<boolean>; | ||
compareSync: (data: string, hash: string) => boolean; | ||
hash: (data: string, { salt, rounds, minor }?: import("./methods/public/hash/types").HashProps) => Promise<string>; | ||
hashSync: (data: string, { salt, rounds, minor }?: import("./methods/public/hashSync/types").HashProps) => string; | ||
}; | ||
export default _default; |
@@ -6,8 +6,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hashSync = exports.hash = void 0; | ||
exports.hashSync = exports.hash = exports.compareSync = exports.compare = void 0; | ||
var compare_1 = __importDefault(require("./methods/public/compare")); | ||
var compareSync_1 = __importDefault(require("./methods/public/compareSync")); | ||
var hash_1 = __importDefault(require("./methods/public/hash")); | ||
var hashSync_1 = __importDefault(require("./methods/public/hashSync")); | ||
exports.compare = compare_1.default; | ||
exports.compareSync = compareSync_1.default; | ||
exports.hash = hash_1.default; | ||
exports.hashSync = hashSync_1.default; | ||
exports.default = { | ||
compare: exports.compare, | ||
compareSync: exports.compareSync, | ||
hash: exports.hash, | ||
@@ -14,0 +20,0 @@ hashSync: exports.hashSync, |
import { FormattedSaltSyncProps } from "./types"; | ||
declare const _default: ({ salt, rounds, minor, }?: FormattedSaltSyncProps) => Promise<string>; | ||
declare const _default: ({ salt, rounds, minor }?: FormattedSaltSyncProps) => string; | ||
export default _default; |
@@ -13,7 +13,7 @@ "use strict"; | ||
if (salt && typeof salt !== 'string') | ||
return Promise.reject(new Error("bcrypt.formattedSalt \"salt\" must be a string.")); | ||
throw new Error("bcrypt.formattedSalt \"salt\" must be a string."); | ||
if (typeof rounds != 'number') | ||
return Promise.reject(new Error("bcrypt.formattedSalt \"rounds\" must be a number. Provided value was \"" + rounds + "\"")); | ||
throw new Error("bcrypt.formattedSalt \"rounds\" must be a number. Provided value was \"" + rounds + "\""); | ||
if (!MINOR.has(minor)) | ||
return Promise.reject(new Error("bcrypt.formattedSalt \"minor\" must be one of the following values " + Array.from(MINOR).join(', ') + ", received \"" + minor + "\".")); | ||
throw new Error("bcrypt.formattedSalt \"minor\" must be one of the following values " + Array.from(MINOR).join(', ') + ", received \"" + minor + "\"."); | ||
var saltHash; | ||
@@ -20,0 +20,0 @@ // Create a 16 byte hash from the provided salt. |
import { HashProps } from "./types"; | ||
declare const _default: (data: string, { salt, rounds, minor, }?: HashProps) => Promise<string>; | ||
declare const _default: (data: string, { salt, rounds, minor }?: HashProps) => Promise<string>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Hashes an input string. Optionally accepts a salt string, |
@@ -61,3 +61,3 @@ "use strict"; | ||
case 0: | ||
if (!data || !data.length) | ||
if (!data || typeof data !== 'string' || !data.length) | ||
return [2 /*return*/, Promise.reject(new Error("bcrypt.hash \"data\" must be a string."))]; | ||
@@ -68,3 +68,3 @@ return [4 /*yield*/, formattedSalt_1.default({ salt: salt, rounds: rounds, minor: minor })]; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
bindings_1.bindings.encrypt(data, saltHash, function (err, result) { return err ? reject(err) : resolve(result); }); | ||
bindings_1.bindings.encrypt(data, saltHash, function (err, result) { return (err ? reject(err) : resolve(result)); }); | ||
})]; | ||
@@ -71,0 +71,0 @@ } |
import { HashProps } from "./types"; | ||
declare const _default: (data: string, { salt, rounds, minor, }?: HashProps) => Promise<string>; | ||
declare const _default: (data: string, { salt, rounds, minor }?: HashProps) => string; | ||
/** | ||
@@ -4,0 +4,0 @@ * Hashes an input string. Optionally accepts a salt string, |
@@ -20,4 +20,4 @@ "use strict"; | ||
var _b = _a === void 0 ? {} : _a, salt = _b.salt, rounds = _b.rounds, minor = _b.minor; | ||
if (!data || !data.length) | ||
return Promise.reject(new Error("bcrypt.hashSync \"data\" must be a string.")); | ||
if (!data || typeof data !== 'string' || !data.length) | ||
throw new Error("bcrypt.hashSync \"data\" must be a string."); | ||
var saltHash = formattedSaltSync_1.default({ salt: salt, rounds: rounds, minor: minor }); | ||
@@ -24,0 +24,0 @@ return bindings_1.bindings.encrypt_sync(data, saltHash); |
{ | ||
"name": "bcrypt-deterministic", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A deterministic bcrypt library for NodeJS.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
110
README.md
@@ -8,5 +8,7 @@ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ralusek/bcrypt-deterministic/blob/master/LICENSE) | ||
## What is this? | ||
This is an implementation of the bcrypt algorithm, with the capability to provide a string salt (which will be turned to a 16 byte hash), and produce a deterministic/consistent/stable output hash. If none is provided, the default/initial bcrypt strategy of generating a random 16 byte hash is used. | ||
## Usage | ||
``` | ||
@@ -17,2 +19,3 @@ $ npm install --save bcrypt-deterministic | ||
Hash with stable output | ||
```javascript | ||
@@ -22,3 +25,3 @@ const { hash } = require('bcrypt-deterministic'); | ||
const salt = 'I am a salt.'; | ||
const data = 'Hello there, I am data.' | ||
const data = 'Hello there, I am data.'; | ||
@@ -33,6 +36,7 @@ // Assume top-level await or inside an async function | ||
Hash with dynamic output due to dynamic salt | ||
```javascript | ||
const { hash } = require('bcrypt-deterministic'); | ||
const data = 'Hello there, I am data.' | ||
const data = 'Hello there, I am data.'; | ||
@@ -47,2 +51,18 @@ // Assume top-level await or inside an async function | ||
Compare with dynamic or fixed salt | ||
```javascript | ||
const { hash, compare } = require('bcrypt-deterministic'); | ||
const password = 'BCryptIsCool'; | ||
// Assume top-level await or inside an async function | ||
const hashedWithFixedSalt = await hash(data, { salt: 'salty', rounds: 10 }); | ||
const hashedWithDynamicSalt = await hash(data, { rounds: 10 }); | ||
await compare(password, hashedWithFixedSalt); // true | ||
await compare(password, hashedWithDynamicSalt); // true | ||
``` | ||
## Version Compatibility | ||
@@ -58,3 +78,3 @@ | ||
> Per bcrypt implementation, only the first 72 bytes of a string are used. Any extra bytes are ignored when matching passwords. Note that this is not the first 72 *characters*. It is possible for a string to contain less than 72 characters, while taking up more than 72 bytes (e.g. a UTF-8 encoded string containing emojis). | ||
> Per bcrypt implementation, only the first 72 bytes of a string are used. Any extra bytes are ignored when matching passwords. Note that this is not the first 72 _characters_. It is possible for a string to contain less than 72 characters, while taking up more than 72 bytes (e.g. a UTF-8 encoded string containing emojis). | ||
@@ -65,3 +85,3 @@ As should be the case with any security tool, this library should be scrutinized by anyone using it. If you find or suspect an issue with the code, please bring it to my attention and I'll spend some time trying to make sure that this tool is as secure as possible. | ||
* An [issue with passwords][jtr] was found with a version of the Blowfish algorithm developed for John the Ripper. This is not present in the OpenBSD version and is thus not a problem for this module. HT [zooko][zooko]. | ||
- An [issue with passwords][jtr] was found with a version of the Blowfish algorithm developed for John the Ripper. This is not present in the OpenBSD version and is thus not a problem for this module. HT [zooko][zooko]. | ||
@@ -76,8 +96,8 @@ ## Compatibility Note | ||
* NodeJS | ||
* `node-gyp` | ||
* Please check the dependencies for this tool at: https://github.com/nodejs/node-gyp | ||
* Windows users will need the options for c# and c++ installed with their visual studio instance. | ||
* Python 2.x | ||
* `OpenSSL` - This is only required to build the `bcrypt` project if you are using versions <= 0.7.7. Otherwise, we're using the builtin node crypto bindings for seed data (which use the same OpenSSL code paths we were, but don't have the external dependency). | ||
- NodeJS | ||
- `node-gyp` | ||
- Please check the dependencies for this tool at: https://github.com/nodejs/node-gyp | ||
- Windows users will need the options for c# and c++ installed with their visual studio instance. | ||
- Python 2.x | ||
- `OpenSSL` - This is only required to build the `bcrypt` project if you are using versions <= 0.7.7. Otherwise, we're using the builtin node crypto bindings for seed data (which use the same OpenSSL code paths we were, but don't have the external dependency). | ||
@@ -89,4 +109,5 @@ ## Install via NPM | ||
``` | ||
***Note:*** OS X users using Xcode 4.3.1 or above may need to run the following command in their terminal prior to installing if errors occur regarding xcodebuild: ```sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer``` | ||
**_Note:_** OS X users using Xcode 4.3.1 or above may need to run the following command in their terminal prior to installing if errors occur regarding xcodebuild: `sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer` | ||
_Pre-built binaries for various NodeJS versions are made available on a best-effort basis._ | ||
@@ -114,31 +135,31 @@ | ||
* `genSaltSync(rounds, minor)` | ||
* `rounds` - [OPTIONAL] - the cost of processing the data. (default - 10) | ||
* `minor` - [OPTIONAL] - minor version of bcrypt to use. (default - b) | ||
* `genSalt(rounds, minor, cb)` | ||
* `rounds` - [OPTIONAL] - the cost of processing the data. (default - 10) | ||
* `minor` - [OPTIONAL] - minor version of bcrypt to use. (default - b) | ||
* `cb` - [OPTIONAL] - a callback to be fired once the salt has been generated. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available. | ||
* `err` - First parameter to the callback detailing any errors. | ||
* `salt` - Second parameter to the callback providing the generated salt. | ||
* `hashSync(data, salt)` | ||
* `data` - [REQUIRED] - the data to be encrypted. | ||
* `salt` - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used (see example under **Usage**). | ||
* `hash(data, salt, cb)` | ||
* `data` - [REQUIRED] - the data to be encrypted. | ||
* `salt` - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used (see example under **Usage**). | ||
* `cb` - [OPTIONAL] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available. | ||
* `err` - First parameter to the callback detailing any errors. | ||
* `encrypted` - Second parameter to the callback providing the encrypted form. | ||
* `compareSync(data, encrypted)` | ||
* `data` - [REQUIRED] - data to compare. | ||
* `encrypted` - [REQUIRED] - data to be compared to. | ||
* `compare(data, encrypted, cb)` | ||
* `data` - [REQUIRED] - data to compare. | ||
* `encrypted` - [REQUIRED] - data to be compared to. | ||
* `cb` - [OPTIONAL] - a callback to be fired once the data has been compared. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available. | ||
* `err` - First parameter to the callback detailing any errors. | ||
* `same` - Second parameter to the callback providing whether the data and encrypted forms match [true | false]. | ||
* `getRounds(encrypted)` - return the number of rounds used to encrypt a given hash | ||
* `encrypted` - [REQUIRED] - hash from which the number of rounds used should be extracted. | ||
- `genSaltSync(rounds, minor)` | ||
- `rounds` - [OPTIONAL] - the cost of processing the data. (default - 10) | ||
- `minor` - [OPTIONAL] - minor version of bcrypt to use. (default - b) | ||
- `genSalt(rounds, minor, cb)` | ||
- `rounds` - [OPTIONAL] - the cost of processing the data. (default - 10) | ||
- `minor` - [OPTIONAL] - minor version of bcrypt to use. (default - b) | ||
- `cb` - [OPTIONAL] - a callback to be fired once the salt has been generated. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available. | ||
- `err` - First parameter to the callback detailing any errors. | ||
- `salt` - Second parameter to the callback providing the generated salt. | ||
- `hashSync(data, salt)` | ||
- `data` - [REQUIRED] - the data to be encrypted. | ||
- `salt` - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used (see example under **Usage**). | ||
- `hash(data, salt, cb)` | ||
- `data` - [REQUIRED] - the data to be encrypted. | ||
- `salt` - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used (see example under **Usage**). | ||
- `cb` - [OPTIONAL] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available. | ||
- `err` - First parameter to the callback detailing any errors. | ||
- `encrypted` - Second parameter to the callback providing the encrypted form. | ||
- `compareSync(data, encrypted)` | ||
- `data` - [REQUIRED] - data to compare. | ||
- `encrypted` - [REQUIRED] - data to be compared to. | ||
- `compare(data, encrypted, cb)` | ||
- `data` - [REQUIRED] - data to compare. | ||
- `encrypted` - [REQUIRED] - data to be compared to. | ||
- `cb` - [OPTIONAL] - a callback to be fired once the data has been compared. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available. | ||
- `err` - First parameter to the callback detailing any errors. | ||
- `same` - Second parameter to the callback providing whether the data and encrypted forms match [true | false]. | ||
- `getRounds(encrypted)` - return the number of rounds used to encrypt a given hash | ||
- `encrypted` - [REQUIRED] - hash from which the number of rounds used should be extracted. | ||
@@ -162,3 +183,2 @@ ## A Note on Rounds | ||
## A Note on Timing Attacks | ||
@@ -186,5 +206,5 @@ | ||
* blowfish.cc - OpenBSD | ||
* bcrypt.cc - OpenBSD | ||
* bcrypt::gen_salt - [gen_salt inclusion to bcrypt][bcryptgs] | ||
* bcrypt_node.cc - kelektiv | ||
- blowfish.cc - OpenBSD | ||
- bcrypt.cc - OpenBSD | ||
- bcrypt::gen_salt - [gen_salt inclusion to bcrypt][bcryptgs] | ||
- bcrypt_node.cc - kelektiv |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155417
48
383
199