mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 23:40:24 +08:00
* fix: 保存 LastResult 时截断字符串过长部分,以避免数据库报错 * refactor: 新增 entity.DbTaskBase 和 persistence.dbTaskBase, 用于实现数据库备份和恢复任务处理相关部分 * fix: aeskey变更后,解密密码出现数组越界访问错误 * fix: 时间属性为零值时,保存到 mysql 数据库报错 * refactor db.infrastructure.service.scheduler * feat: 实现立即备份功能 * refactor db.infrastructure.service.db_instance * refactor: 从数据库中获取数据库备份目录、mysql文件路径等配置信息 * fix: 数据库备份和恢复问题 * fix: 修改 .gitignore 文件,忽略数据库备份目录和数据库程序目录
31 lines
678 B
Go
31 lines
678 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"mayfly-go/pkg/utils/assert"
|
|
"mayfly-go/pkg/utils/cryptox"
|
|
)
|
|
|
|
type Aes struct {
|
|
Key string `yaml:"key"`
|
|
}
|
|
|
|
// 编码并base64
|
|
func (a *Aes) EncryptBase64(data []byte) (string, error) {
|
|
return cryptox.AesEncryptBase64(data, []byte(a.Key))
|
|
}
|
|
|
|
// base64解码后再aes解码
|
|
func (a *Aes) DecryptBase64(data string) ([]byte, error) {
|
|
return cryptox.AesDecryptBase64(data, []byte(a.Key))
|
|
}
|
|
|
|
func (a *Aes) Valid() {
|
|
if a.Key == "" {
|
|
return
|
|
}
|
|
aesKeyLen := len(a.Key)
|
|
assert.IsTrue(aesKeyLen == 16 || aesKeyLen == 24 || aesKeyLen == 32,
|
|
fmt.Sprintf("config.yml之 [aes.key] 长度需为16、24、32位长度, 当前为%d位", aesKeyLen))
|
|
}
|