@sequencemedia/pbkdf2 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +82 -4
  2. package/package.json +10 -1
package/README.md CHANGED
@@ -1,13 +1,91 @@
1
1
  # @sequencemedia/pbkdf2
2
2
 
3
- A password can be validated against a `hash` and `salt` (and the number of `iterations` that were used to compute it)
3
+ ## Compare a given password to a `hash` and `salt`
4
4
 
5
- Both the `hash` and `salt` are expected from the command line to be strings in _Base64_ format
5
+ Exposes the crypto `pbkdf2` utilities as `async` functions for Node and the shell
6
+
7
+ ES functions are exported from the package root alongside a TS definition
8
+
9
+ ## Password validation by `hash` and `salt` comparison
10
+
11
+ A password can be compared with a `hash` and `salt` (and the number of `iterations` that were used to compute it) to determine whether it is valid
12
+
13
+ The ES functions expect the same argument types as the underlying Node utilities
14
+
15
+ - The `hash` is a `Buffer`
16
+ - The `salt` is a `String`
17
+ - `iterations` is a `Number`
18
+
19
+ Etc.
20
+
21
+ ### `compare`
22
+
23
+ The password is expected as the first argument, while the others are fields on a params object
24
+
25
+ ```javascript
26
+ const isValid = await compare(password, { hash, salt, iterations, keylen, digest })
27
+ ```
28
+
29
+ ### `hash`
30
+
31
+ As with `compare`, the password is expected as the first argument, while the others are fields on a params object (except for `hash` which can of course be omitted)
32
+
33
+ ```javascript
34
+ const value = await hash(password, { salt, iterations, keylen, digest })
35
+ ```
36
+
37
+ ### `salt`
38
+
39
+ An `async` wrapper around `crypto.randomBytes` to _generate_ a salt from the salt size
40
+
41
+ ```javascript
42
+ const value = await salt(size)
43
+ ```
44
+ ## In the shell
45
+
46
+ Scripts are exposed to `npm` in the package and each script can of course be invoked from the command line directly in the shell
47
+
48
+ ```json
49
+ {
50
+ "compare": "node scripts/compare.mjs",
51
+ "hash": "node scripts/hash.mjs",
52
+ "salt": "node scripts/salt.mjs"
53
+ }
54
+ ```
55
+
56
+ Where required, both the `hash` and `salt` arguments are expected from the command line to be strings in _Base64_ format. Both `iterations` and `keylen` are coerced from strings to numbers
57
+
58
+ ```bash
59
+ npm run compare -- \
60
+ --password <PASSWORD> \
61
+ --hash <HASH> \
62
+ --salt <SALT> \
63
+ --keylen <KEY LENGTH> \
64
+ --iterations <ITERATIONS> \
65
+ --digest <DIGEST>
66
+ ```
67
+
68
+ ```bash
69
+ ./scripts/compare.mjs \
70
+ --password <PASSWORD> \
71
+ --hash <HASH> \
72
+ --salt <SALT> \
73
+ --keylen <KEY LENGTH> \
74
+ --iterations <ITERATIONS> \
75
+ --digest <DIGEST>
76
+ ```
77
+
78
+ Etc.
6
79
 
7
80
  - The `hash` is decoded to a `Buffer`
8
- - The `salt` is transformed from _Base64_ into _ASCII_
81
+ - The `salt` is transformed from a _Base64_ into an _ASCII_ `String`
82
+
83
+ ## Tests
9
84
 
10
85
  ```bash
11
86
  npm test
12
- bash ./compare.sh
87
+ ```
88
+
89
+ ```bash
90
+ ./compare.sh
13
91
  ```
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@sequencemedia/pbkdf2",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
+ "keywords": [
5
+ "pbkdf2",
6
+ "crypto",
7
+ "compare",
8
+ "hash",
9
+ "salt",
10
+ "ecmascript",
11
+ "typescript"
12
+ ],
4
13
  "main": "./index.mjs",
5
14
  "type": "module",
6
15
  "author": {