Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Mar 17, 2023
1 parent 3853d29 commit 6d00393
Show file tree
Hide file tree
Showing 66 changed files with 1,217 additions and 1,584 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ body:
attributes:
label: lakego-admin 版本
description: 请输入您当前使用的项目版本?
placeholder: 1.0.5
placeholder: 1.0.1
validations:
required: true
- type: input
id: golang
attributes:
label: Golang 版本
description: 请输入您当前使用的 Golang 版本?
placeholder: go 1.18
placeholder: go 1.16
validations:
required: true
- type: dropdown
Expand Down
18 changes: 10 additions & 8 deletions app/example/controller/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (this *Data) Error(ctx *gin.Context) {
newStrData := str.LowerCamel(strData)

// 时间
datebin.SetTimezone(datebin.Eire)
datebin.SetTimezone(datebin.Chongqing)
date := datebin.
Now().
ToFormatString("Y/m/d H:i:s")
Expand Down Expand Up @@ -232,13 +232,13 @@ func (this *Data) Error(ctx *gin.Context) {
// rsaEnKey := cryptobin_tool.EncodeDerToPem([]byte(rsaPriDer), "ENCRYPTED PRIVATE KEY")

// 签名
hashData := hash.FromString("123测试abc").MD2().ToString()
hashData2 := hash.Murmur32("测试测试")
hashData := hash.FromString("123测试abc").MD2().ToHexString()
hashData2 := hash.FromString("测试测试").Murmur32().ToHexString()

// 编码
encodeStr := encoding.FromString("test-data").ToBase64String()
encodeStr2 := encoding.FromBase64String("dGVzdC1kYXRh").ToString()
encodeStr3 := encoding.FromConvertHex("573d").ToConvertDecString()
encodeStr := encoding.FromString("test-data").Base64Encode().ToString()
encodeStr2 := encoding.FromString("dGVzdC1kYXRh").Base64Decode().ToString()
encodeStr3 := encoding.New().ConvertHexDecode("573d").ConvertDecStringEncode()

/*
encodeStr3 = encoding.FromString("asdsa123").ToBase45String()
Expand Down Expand Up @@ -315,7 +315,7 @@ func (this *Data) Error(ctx *gin.Context) {

// sm2 签名
sm2key := "NBtl7WnuUtA2v5FaebEkU0/Jj1IodLGT6lQqwkzmd2E="
sm2keyBytes := encoding.FromBase64String(sm2key).ToBytes()
sm2keyBytes := encoding.FromString(sm2key).Base64Decode().ToBytes()
sm2data := `{"request":{"body":{"TEST":"中文","TEST2":"!@#$%^&*()","TEST3":12345,"TEST4":[{"arrItem1":"qaz","arrItem2":123,"arrItem3":true,"arrItem4":"中文"}],"buscod":"N02030"},"head":{"funcode":"DCLISMOD","userid":"N003261207"}},"signature":{"sigdat":"__signature_sigdat__"}}`
sm2userid := "N0032612070000000000000000"
sm2userid = sm2userid[0:16]
Expand Down Expand Up @@ -373,7 +373,9 @@ func (this *Data) Error(ctx *gin.Context) {
crcData2 := crc.ToHexString(crcData, "crc6")

// hashCrc32Data
hashCrc32Data := hash.CRC32Koopman(string(crc32Hex))
hashCrc32Data := hash.FromBytes(crc32Hex).
CRC32_Koopman().
ToHexString()

// crc12
crc12Hex, _ := hex.DecodeString("31303432")
Expand Down
6 changes: 5 additions & 1 deletion pkg/lakego-app/doak-admin/admin/auth/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func NewWithAud(aud string) *token.Token {

// 获取接收方
func GetJwtAud(ctx *router.Context) string {
aud := hash.MD5(router.GetRequestIp(ctx) + router.GetHeaderByName(ctx, "HTTP_USER_AGENT"))
aud := md5(router.GetRequestIp(ctx) + router.GetHeaderByName(ctx, "HTTP_USER_AGENT"))

return aud
}

func md5(data string) string {
return hash.FromString(data).MD5().ToHexString()
}
7 changes: 4 additions & 3 deletions pkg/lakego-app/doak-admin/admin/cmd/import_apiroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

"github.com/deatil/go-hash/hash"
"github.com/deatil/go-datebin/datebin"
"github.com/deatil/go-encoding/encoding"
"github.com/deatil/lakego-filesystem/filesystem"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/deatil/lakego-doak/lakego/command"

"github.com/deatil/lakego-doak-admin/admin/model"
"github.com/deatil/lakego-doak-admin/admin/support/utils"
)

/**
Expand Down Expand Up @@ -54,7 +54,8 @@ func ImportApiRoute() {
var routes map[string]any

// 转换为 map
err = encoding.Unmarshal([]byte(swaggerInfo), &routes)
err = encoding.FromString(swaggerInfo).
JSONIteratorDecode(&routes).Error
if err != nil {
fmt.Println("api 信息错误")
return
Expand Down Expand Up @@ -82,7 +83,7 @@ func ImportApiRoute() {

slug := data.Value("x-lakego.slug").ToString()
if slug == "" {
slug = hash.MD5(datebin.NowDatetimeString() + random.String(15))
slug = utils.MD5(datebin.NowDatetimeString() + random.String(15))
}

// 排序
Expand Down
6 changes: 3 additions & 3 deletions pkg/lakego-app/doak-admin/admin/cmd/passport_logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package cmd
import (
"fmt"

"github.com/deatil/go-hash/hash"
"github.com/deatil/go-datebin/datebin"
"github.com/deatil/lakego-doak/lakego/command"
"github.com/deatil/lakego-doak/lakego/facade/cache"

"github.com/deatil/lakego-doak-admin/admin/model"
"github.com/deatil/lakego-doak-admin/admin/auth/auth"
"github.com/deatil/lakego-doak-admin/admin/support/utils"
)

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ func init() {
func PassportLogout() {
c := cache.New()

if c.Has(hash.MD5(refreshToken)) {
if c.Has(utils.MD5(refreshToken)) {
fmt.Println("refreshToken 已失效")
return
}
Expand All @@ -75,7 +75,7 @@ func PassportLogout() {
iat := jwter.GetFromTokenClaims(claims, "iat")
refreshTokenExpiresIn := exp.(float64) - iat.(float64)

c.Put(hash.MD5(refreshToken), "no", int64(refreshTokenExpiresIn))
c.Put(utils.MD5(refreshToken), "no", int64(refreshTokenExpiresIn))

model.NewAdmin().
Where("id = ?", refreshAdminid).
Expand Down
4 changes: 2 additions & 2 deletions pkg/lakego-app/doak-admin/admin/cmd/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package cmd
import (
"fmt"

"github.com/deatil/go-hash/hash"
"github.com/deatil/lakego-doak/lakego/command"

"github.com/deatil/lakego-doak-admin/admin/model"
"github.com/deatil/lakego-doak-admin/admin/support/utils"
auth_password "github.com/deatil/lakego-doak-admin/admin/password"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func ResetPassword() {
return
}

password = hash.MD5(password)
password = utils.MD5(password)

// 查询
result := map[string]any{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/lakego-app/doak-admin/admin/controller/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"

"github.com/deatil/go-goch/goch"
"github.com/deatil/go-hash/hash"
"github.com/deatil/go-tree/tree"
"github.com/deatil/go-datebin/datebin"

Expand All @@ -19,6 +18,7 @@ import (
"github.com/deatil/lakego-doak-admin/admin/permission"
"github.com/deatil/lakego-doak-admin/admin/auth/auth"
"github.com/deatil/lakego-doak-admin/admin/auth/admin"
"github.com/deatil/lakego-doak-admin/admin/support/utils"
auth_password "github.com/deatil/lakego-doak-admin/admin/password"
admin_validate "github.com/deatil/lakego-doak-admin/admin/validate/admin"
admin_repository "github.com/deatil/lakego-doak-admin/admin/repository/admin"
Expand Down Expand Up @@ -836,7 +836,7 @@ func (this *Admin) Logout(ctx *router.Context) {

c := cache.New()

if c.Has(hash.MD5(refreshToken)) {
if c.Has(utils.MD5(refreshToken)) {
this.Error(ctx, "refreshToken已失效")
return
}
Expand Down Expand Up @@ -866,7 +866,7 @@ func (this *Admin) Logout(ctx *router.Context) {
return
}

c.Put(hash.MD5(refreshToken), "no", int64(refreshTokenExpiresIn))
c.Put(utils.MD5(refreshToken), "no", int64(refreshTokenExpiresIn))

model.NewAdmin().
Where("id = ?", refreshAdminid).
Expand Down
4 changes: 2 additions & 2 deletions pkg/lakego-app/doak-admin/admin/controller/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controller

import (
"github.com/deatil/go-goch/goch"
"github.com/deatil/go-hash/hash"
"github.com/deatil/go-datebin/datebin"
"github.com/deatil/lakego-filesystem/filesystem"

Expand All @@ -13,6 +12,7 @@ import (

"github.com/deatil/lakego-doak-admin/admin/model"
"github.com/deatil/lakego-doak-admin/admin/support/url"
"github.com/deatil/lakego-doak-admin/admin/support/utils"
)

/**
Expand Down Expand Up @@ -347,7 +347,7 @@ func (this *Attachment) DownloadCode(ctx *router.Context) {
}

// 添加到缓存
code := hash.MD5(goch.ToString(datebin.NowTime()) + random.String(10))
code := utils.MD5(goch.ToString(datebin.NowTime()) + random.String(10))
cache.New().Put(code, result["id"].(string), 300)

// 数据输出
Expand Down
10 changes: 5 additions & 5 deletions pkg/lakego-app/doak-admin/admin/controller/passport.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controller

import (
"github.com/deatil/go-hash/hash"
"github.com/deatil/go-datebin/datebin"

"github.com/deatil/lakego-doak/lakego/router"
Expand All @@ -12,6 +11,7 @@ import (

"github.com/deatil/lakego-doak-admin/admin/model"
"github.com/deatil/lakego-doak-admin/admin/auth/auth"
"github.com/deatil/lakego-doak-admin/admin/support/utils"
"github.com/deatil/lakego-doak-admin/admin/support/http/code"
auth_password "github.com/deatil/lakego-doak-admin/admin/password"
passport_validate "github.com/deatil/lakego-doak-admin/admin/validate/passport"
Expand Down Expand Up @@ -181,7 +181,7 @@ func (this *Passport) RefreshToken(ctx *router.Context) {
}

c := cache.New()
refreshTokenPutTime, _ := c.Get(hash.MD5(refreshToken.(string)))
refreshTokenPutTime, _ := c.Get(utils.MD5(refreshToken.(string)))
refreshTokenPutTime = refreshTokenPutTime.(string)
if refreshTokenPutTime != "" {
this.Error(ctx, "refreshToken已失效", code.JwtRefreshTokenFail)
Expand Down Expand Up @@ -249,7 +249,7 @@ func (this *Passport) Logout(ctx *router.Context) {
}

c := cache.New()
refreshTokenPutString, _ := c.Get(hash.MD5(refreshToken.(string)))
refreshTokenPutString, _ := c.Get(utils.MD5(refreshToken.(string)))
refreshTokenPutString = refreshTokenPutString.(string)
if refreshTokenPutString != "" {
this.Error(ctx, "refreshToken 已失效", code.JwtRefreshTokenFail)
Expand Down Expand Up @@ -285,8 +285,8 @@ func (this *Passport) Logout(ctx *router.Context) {
accessToken, _ := ctx.Get("access_token")

// 加入黑名单
c.Put(hash.MD5(accessToken.(string)), "no", int64(refreshTokenExpiresIn))
c.Put(hash.MD5(refreshToken.(string)), "no", int64(refreshTokenExpiresIn))
c.Put(utils.MD5(accessToken.(string)), "no", int64(refreshTokenExpiresIn))
c.Put(utils.MD5(refreshToken.(string)), "no", int64(refreshTokenExpiresIn))

// 数据输出
this.Success(ctx, "退出成功")
Expand Down
6 changes: 5 additions & 1 deletion pkg/lakego-app/doak-admin/admin/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ func EncryptPassword(password string) (pass string, encrypt string) {
* @return password, encrypt
*/
func EncryptPasswordWithEncrypt(password string, encrypt string) string {
return hash.MD5(hash.MD5(password + encrypt) + GetPasswordSalt())
return md5(md5(password + encrypt) + GetPasswordSalt())
}

// 密码通用盐
func GetPasswordSalt() string {
return config.New("auth").GetString("passport.password-salt")
}

func md5(data string) string {
return hash.FromString(data).MD5().ToHexString()
}
17 changes: 12 additions & 5 deletions pkg/lakego-app/doak-admin/admin/support/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (this *Token) MakeJWT() *jwt.JWT {
privateKeyPassword := this.GetStringConfig("jwt.private-key-password", "")

// 解析 base64
secret = encoding.Base64Decode(secret)
secret = base64Decode(secret)

// 格式化公钥和私钥
privateKey = this.FormatPath(privateKey)
Expand All @@ -169,7 +169,7 @@ func (this *Token) MakeJWT() *jwt.JWT {
publicKeyData, _ := this.ReadDataFromFile(publicKey)

// 私钥密码
privateKeyPassword = encoding.Base64Decode(privateKeyPassword)
privateKeyPassword = base64Decode(privateKeyPassword)

nowTime := time.Now().Unix()

Expand Down Expand Up @@ -222,7 +222,7 @@ func (this *Token) MakeAccessToken(claims map[string]string) (token string, err

passphraseIv := this.GetStringConfig("jwt.passphrase-iv", "")
passphrase := this.GetStringConfig("jwt.passphrase", "")
passphrase = encoding.Base64Decode(passphrase)
passphrase = base64Decode(passphrase)

jwtHandle := this.
MakeJWT().
Expand Down Expand Up @@ -253,7 +253,7 @@ func (this *Token) MakeRefreshToken(claims map[string]string) (token string, err

passphraseIv := this.GetStringConfig("jwt.passphrase-iv", "")
passphrase := this.GetStringConfig("jwt.passphrase", "")
passphrase = encoding.Base64Decode(passphrase)
passphrase = base64Decode(passphrase)

jwtHandle := this.
MakeJWT().
Expand Down Expand Up @@ -405,7 +405,7 @@ func (this *Token) GetDataFromTokenClaims(claims jwt.MapClaims, key string) stri

passphraseIv := this.GetStringConfig("jwt.passphrase-iv", "")
passphrase := this.GetStringConfig("jwt.passphrase", "")
passphrase = encoding.Base64Decode(passphrase)
passphrase = base64Decode(passphrase)

if passphrase != "" {
data = this.Decode(data, passphrase, passphraseIv)
Expand Down Expand Up @@ -466,3 +466,10 @@ func (this *Token) FormatPath(file string) string {

return filename
}

func base64Decode(data string) string {
return encoding.
FromString(data).
Base64Decode().
ToString()
}
9 changes: 9 additions & 0 deletions pkg/lakego-app/doak-admin/admin/support/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package utils

import (
"github.com/deatil/go-hash/hash"
)

func MD5(data string) string {
return hash.FromString(data).MD5().ToHexString()
}
17 changes: 17 additions & 0 deletions pkg/lakego-pkg/go-cryptobin/jceks/uber.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package jceks

import (
"io"
"bytes"
)

const (
UberVersionV1 = 1
)
Expand All @@ -25,6 +30,18 @@ func NewUBER() *UBER {
return uber
}

// LoadUberFromReader
func LoadUberFromReader(reader io.Reader, password string) (*UBER, error) {
buf := bytes.NewBuffer(nil)

// 保存
if _, err := io.Copy(buf, reader); err != nil {
return nil, err
}

return LoadUberFromBytes(buf.Bytes(), password)
}

// LoadUberFromBytes loads the key store from the bytes data.
func LoadUberFromBytes(data []byte, password string) (*UBER, error) {
uber := &UBER{
Expand Down
Loading

0 comments on commit 6d00393

Please sign in to comment.