-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinworker.js
57 lines (55 loc) · 2.5 KB
/
pinworker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Buffer } from 'buffer'
import { pbkdf2 } from 'pbkdf2'
import { createDecipher } from 'chacha-js'
(async () => {
self.addEventListener('message', message => {
const {salt, nonce, encrypted, tag} = message.data
const saltBuf = Buffer.from(salt, 'hex')
const nonceBuf = Buffer.from(nonce, 'hex')
const encryptedBuf = Buffer.from(encrypted, 'hex')
const tagBuf = Buffer.from(tag, 'hex')
let success = false
for (let one = 0; one < 10; one++) {
for (let two = 0; two < 10; two++) {
for (let three = 0; three < 10; three++) {
for (let four = 0; four < 10; four++) {
const pinString = one.toString() + two.toString() +
three.toString() + four.toString()
postMessage({
pin: pinString,
key: "Test",
decrypted: null,
})
const pin = new Buffer.from([one, two, three, four])
pbkdf2(pin, saltBuf, 12983, 32, 'sha512',
(err, key) => {
if (!err) {
const dec = createDecipher(key, nonceBuf)
dec.setAuthTag(tagBuf)
try {
let decrypted = dec.update(encryptedBuf,
'', 'hex')
decrypted += dec.final('hex')
success = true
postMessage({
pin: pinString,
key: key.toString('hex'),
decrypted: decrypted,
})
} catch(e) {
if (!success) {
postMessage({
pin: pinString,
key: key.toString('hex'),
decrypted: null,
})
}
}
}
})
}
}
}
}
})
})()