Skip to content

Commit df007d2

Browse files
committed
Update utils.js
1 parent d1b6be3 commit df007d2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

utils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ let validateString = (string) => {
372372

373373
// hash string
374374
let hashCode = (string) => {
375-
var hash = 0, i, chr;
375+
let hash = 0, i, chr;
376376
if (string.length === 0) return hash;
377377
for (i = 0; i < string.length; i++) {
378378
chr = string.charCodeAt(i);
@@ -383,6 +383,17 @@ let hashCode = (string) => {
383383
}
384384

385385

386+
// generate SHA
387+
let generateSHA = (len) => {
388+
let dec2hex = (dec) => {
389+
return dec.toString(16).padStart(2, '0');
390+
}
391+
const arr = new Uint8Array((len || 40) / 2);
392+
window.crypto.getRandomValues(arr);
393+
return Array.from(arr, dec2hex).join('');
394+
}
395+
396+
386397
// asynchronous thread
387398

388399
let asyncThread = (callback, time) => {

0 commit comments

Comments
 (0)