-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
66 lines (52 loc) · 1.35 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package common
import (
"context"
"github.com/litsoftware/litmedia/internal/ent"
app2 "github.com/litsoftware/litmedia/internal/ent/app"
"github.com/litsoftware/litmedia/internal/pkg/config"
"github.com/litsoftware/litmedia/internal/pkg/config/orm"
"github.com/litsoftware/litmedia/pkg/aes"
)
func DecryptAppInfo(app *ent.App) error {
key := []byte(config.GetString("app.system_aes"))
appPub, err := aes.Decrypt(key, app.EncryptedAppPublicKey)
if err != nil {
return err
}
appPriv, err := aes.Decrypt(key, app.EncryptedAppPrivateKey)
if err != nil {
return err
}
rsaPub, err := aes.Decrypt(key, app.EncryptedOperatorRsaPublicKey)
if err != nil {
return err
}
app.EncryptedAppPublicKey = appPub
app.EncryptedAppPrivateKey = appPriv
app.EncryptedOperatorRsaPublicKey = rsaPub
return nil
}
func EncryptAppInfo() {
}
func GetAppById(ctx context.Context, id int) (*ent.App, error) {
app, err := orm.GetClient().App.Query().Where(app2.ID(id)).First(ctx)
if err != nil {
return nil, err
}
err = DecryptAppInfo(app)
if err != nil {
return nil, err
}
return app, nil
}
func GetAppByAppId(ctx context.Context, AppId string) (*ent.App, error) {
app, err := orm.GetClient().App.Query().Where(app2.AppID(AppId)).First(ctx)
if err != nil {
return nil, err
}
err = DecryptAppInfo(app)
if err != nil {
return nil, err
}
return app, nil
}