You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-23
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,10 @@
1
1
scrypt
2
2
======
3
3
4
-
The [scrypt](https://en.wikipedia.org/wiki/Scrypt) password-base key derivation function (pbkdf) is an algorithm designed to be brute-force resistant that converts human readable passwords into fixed length arrays of bytes, which can then be used as a key for symmetric block ciphers, private keys, et cetera.
4
+
The [scrypt](https://en.wikipedia.org/wiki/Scrypt) password-base key derivation
5
+
function (pbkdf) is an algorithm designed to be brute-force resistant that
6
+
converts human readable passwords into fixed length arrays of bytes, which can
7
+
then be used as a key for symmetric block ciphers, private keys, et cetera.
5
8
6
9
### Features:
7
10
-**Non-blocking** - Gives other events in the event loop opportunities to run (asynchronous)
@@ -40,12 +43,28 @@ npm install scrypt-js
40
43
API
41
44
---
42
45
46
+
**scrypt . scrypt ( password , salt , N , r , p , dkLen [ , progressCallback ] )***=> Promise<Uint8Array>*
47
+
48
+
Compute the scrypt PBKDF asynchronously using a Promise. If *progressCallback* is
49
+
provided, it is periodically called with a single parameter, a number between 0 and
50
+
1 (inclusive) indicating the completion progress; it will **always** emit 0 at the
51
+
beginning and 1 at the end, and numbers between may repeat.
52
+
53
+
**scrypt . syncScrypt ( password , salt , N , r , p , dkLen )***=> Uint8Array*
54
+
55
+
Compute the scrypt PBKDF synchronously. Keep in mind this may stall UI and other tasks and the
constkeyPromise=scrypt.scrypt(password, salt, N, r, p, dkLen, updateInterface);
69
88
70
-
} else {
71
-
// update UI with progress complete
72
-
updateInterface(progress);
73
-
}
89
+
keyPromise.then(function(key) {
90
+
console.log("Derived Key (async): ", key);
74
91
});
92
+
93
+
// Sync
94
+
constkey=scrypt.syncScrypt(password, salt, N, r, p, dkLen);
95
+
console.log("Derived Key (sync): ", key);
75
96
</script>
76
97
</body>
77
98
</html>
@@ -131,14 +152,22 @@ true
131
152
132
153
**Normalizing**
133
154
134
-
The `normalize()` method of a string can be used to convert a string to a specific form. Without going into too much detail, I generally recommend `NFKC`, however if you wish to dive deeper into this, a nice short summary can be found in Pythons [unicodedata module](https://docs.python.org/2/library/unicodedata.html#unicodedata.normalize)'s documentation.
155
+
The `normalize()` method of a string can be used to convert a string to a
156
+
specific form. Without going into too much detail, I generally recommend
157
+
`NFKC`, however if you wish to dive deeper into this, a nice short summary
158
+
can be found in Pythons [unicodedata module](https://docs.python.org/2/library/unicodedata.html#unicodedata.normalize)'s
159
+
documentation.
135
160
136
-
For browsers without `normalize()` support, the [npm unorm module](https://www.npmjs.com/package/unorm) can be used to polyfill strings.
161
+
For browsers without `normalize()` support, the [npm unorm module](https://www.npmjs.com/package/unorm)
162
+
can be used to polyfill strings.
137
163
138
164
139
165
**Another example of encoding woes**
140
166
141
-
One quick story I will share is a project which used the `SHA256(encodeURI(password))` as a key, which (ignoring [rainbow table attacks](https://en.wikipedia.org/wiki/Rainbow_table)) had an unfortunate consequence of old web browsers replacing spaces with `+` while on new web browsers, replacing it with a `%20`, causing issues for anyone who used spaces in their password.
167
+
One quick story I will share is a project which used the `SHA256(encodeURI(password))` as
168
+
a key, which (ignoring [rainbow table attacks](https://en.wikipedia.org/wiki/Rainbow_table))
169
+
had an unfortunate consequence of old web browsers replacing spaces with `+` while on new web
170
+
browsers, replacing it with a `%20`, causing issues for anyone who used spaces in their password.
142
171
143
172
144
173
### Suggestions
@@ -161,7 +190,8 @@ npm test
161
190
Special Thanks
162
191
--------------
163
192
164
-
I would like to thank @dchest for his [scrypt-async](https://github.com/dchest/scrypt-async-js) library and for his assistance providing feedback and optimization suggestions.
193
+
I would like to thank @dchest for his [scrypt-async](https://github.com/dchest/scrypt-async-js)
194
+
library and for his assistance providing feedback and optimization suggestions.
165
195
166
196
167
197
License
@@ -183,8 +213,7 @@ References
183
213
Donations
184
214
---------
185
215
186
-
Obviously, it's all licensed under the MIT license, so use it as you wish; but if you'd like to buy me a coffee, I won't complain. =)
216
+
Obviously, it's all licensed under the MIT license, so use it as you wish;
217
+
but if you'd like to buy me a coffee, I won't complain. =)
0 commit comments