@sequencemedia/pbkdf2 1.0.7 → 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 +78 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,21 +1,91 @@
1
1
  # @sequencemedia/pbkdf2
2
2
 
3
- ES functions are exported from package root alongside a TS definition
3
+ ## Compare a given password to a `hash` and `salt`
4
4
 
5
- ## Password validation
5
+ Exposes the crypto `pbkdf2` utilities as `async` functions for Node and the shell
6
6
 
7
- A password can be validated against a `hash` and `salt` (and the number of `iterations` that were used to compute it)
7
+ ES functions are exported from the package root alongside a TS definition
8
8
 
9
- Both the `hash` and `salt` are expected from the command line to be strings in _Base64_ format
9
+ ## Password validation by `hash` and `salt` comparison
10
10
 
11
- - The `hash` is decoded to a `Buffer`
12
- - The `salt` is transformed from _Base64_ into _ASCII_
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
13
45
 
14
- You can use these utilities from the shell or as part of a Node application
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.
79
+
80
+ - The `hash` is decoded to a `Buffer`
81
+ - The `salt` is transformed from a _Base64_ into an _ASCII_ `String`
15
82
 
16
83
  ## Tests
17
84
 
18
85
  ```bash
19
86
  npm test
20
- bash ./compare.sh
87
+ ```
88
+
89
+ ```bash
90
+ ./compare.sh
21
91
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequencemedia/pbkdf2",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "keywords": [
5
5
  "pbkdf2",
6
6
  "crypto",