-
Notifications
You must be signed in to change notification settings - Fork 163
/
encryptor.go
37 lines (31 loc) · 902 Bytes
/
encryptor.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
package miniProgram
import (
"encoding/base64"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/support"
)
type Encryptor struct {
BaseEncryptor *kernel.Encryptor
aes *support.AES
}
func NewEncryptor(appID, token, aesKey string) (*Encryptor, error) {
baseEncryptor, err := kernel.NewEncryptor(appID, token, aesKey)
if err != nil {
return nil, err
}
return &Encryptor{
BaseEncryptor: baseEncryptor,
aes: &support.AES{},
}, nil
}
func (encryptor Encryptor) DecryptData(encrypted string, sessionKey string, iv string) ([]byte, *support.CryptError) {
encryptData := encrypted
_key, _ := base64.StdEncoding.DecodeString(sessionKey)
_iv, _ := base64.StdEncoding.DecodeString(iv)
aes := support.AES{}
data, err := aes.Decrypt(encryptData, _key, _iv)
if err != nil {
return nil, err
}
return data, err
}