feat: 资源密码加密处理&登录密码加密加强等

This commit is contained in:
meilin.huang
2022-08-02 21:44:01 +08:00
parent daa2ef5203
commit 12f8cf0111
33 changed files with 340 additions and 51 deletions

27
server/pkg/config/aes.go Normal file
View File

@@ -0,0 +1,27 @@
package config
import (
"fmt"
"mayfly-go/pkg/utils"
"mayfly-go/pkg/utils/assert"
)
type Aes struct {
Key string `yaml:"key"`
}
// 编码并base64
func (a *Aes) EncryptBase64(data []byte) (string, error) {
return utils.AesEncryptBase64(data, []byte(a.Key))
}
// base64解码后再aes解码
func (a *Aes) DecryptBase64(data string) ([]byte, error) {
return utils.AesDecryptBase64(data, []byte(a.Key))
}
func (j *Aes) Valid() {
aesKeyLen := len(j.Key)
assert.IsTrue(aesKeyLen == 16 || aesKeyLen == 24 || aesKeyLen == 32,
fmt.Sprintf("config.yml之 [aes.key] 长度需为16、24、32位长度, 当前为%d位", aesKeyLen))
}