@sequencemedia/pbkdf2 1.0.7 → 1.0.9
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.
- package/README.md +90 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,103 @@
|
|
|
1
1
|
# @sequencemedia/pbkdf2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Compare a given password to a `hash` and `salt`
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Exposes the crypto `pbkdf2` utilities as `async` functions for Node and the shell
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
ES functions are exported from the package root alongside a TS definition
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Password validation by `hash` and `salt` comparison
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
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, {
|
|
27
|
+
hash,
|
|
28
|
+
salt,
|
|
29
|
+
iterations,
|
|
30
|
+
keylen,
|
|
31
|
+
digest
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### `hash`
|
|
36
|
+
|
|
37
|
+
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)
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const value = await hash(password, {
|
|
41
|
+
hash,
|
|
42
|
+
iterations,
|
|
43
|
+
keylen,
|
|
44
|
+
digest
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `salt`
|
|
49
|
+
|
|
50
|
+
An `async` wrapper around `crypto.randomBytes()` to _generate_ a salt from the salt size
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
const value = await salt(size)
|
|
54
|
+
```
|
|
13
55
|
|
|
14
|
-
|
|
56
|
+
## In the shell
|
|
57
|
+
|
|
58
|
+
Scripts are exposed to `npm` in the package and each script can of course be invoked from the command line directly in the shell
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"compare": "node scripts/compare.mjs",
|
|
63
|
+
"hash": "node scripts/hash.mjs",
|
|
64
|
+
"salt": "node scripts/salt.mjs"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
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
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm run compare -- \
|
|
72
|
+
--password <PASSWORD> \
|
|
73
|
+
--hash <HASH> \
|
|
74
|
+
--salt <SALT> \
|
|
75
|
+
--keylen <KEY LENGTH> \
|
|
76
|
+
--iterations <ITERATIONS> \
|
|
77
|
+
--digest <DIGEST>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
./scripts/compare.mjs \
|
|
82
|
+
--password <PASSWORD> \
|
|
83
|
+
--hash <HASH> \
|
|
84
|
+
--salt <SALT> \
|
|
85
|
+
--keylen <KEY LENGTH> \
|
|
86
|
+
--iterations <ITERATIONS> \
|
|
87
|
+
--digest <DIGEST>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Etc.
|
|
91
|
+
|
|
92
|
+
- The `hash` is decoded to a `Buffer`
|
|
93
|
+
- The `salt` is transformed from a _Base64_ into an _ASCII_ `String`
|
|
15
94
|
|
|
16
95
|
## Tests
|
|
17
96
|
|
|
18
97
|
```bash
|
|
19
98
|
npm test
|
|
20
|
-
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
./compare.sh
|
|
21
103
|
```
|