1 Star 0 Fork 0

linngc / central-mirror

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
str_encode.go 706 Bytes
一键复制 编辑 原始数据 按行查看 历史
linngc 提交于 2024-03-04 09:41 . 合并plugin包代码
// Package str
// @Link https://gitee.com/linngc/central-mirror
// @Copyright Copyright (c) 2022 central CLI
// @Author linngc
// @License
package str
import (
"encoding/base64"
"fmt"
"github.com/gogf/gf/v2/text/gstr"
)
// GetAuthEncode 加密用户字符串
func GetAuthEncode(user, pwd string) string {
base := fmt.Sprintf("%s:%s", user, pwd)
return base64.StdEncoding.EncodeToString([]byte(base))
}
// GetAuthDecode 解密用户字符串
func GetAuthDecode(authorization string) (user, pwd string, err error) {
base, err := base64.StdEncoding.DecodeString(authorization)
if err != nil {
return "", "", err
}
s := string(base)
return s[:gstr.Pos(s, ":")], s[gstr.Pos(s, ":")+1:], err
}
Go
1
https://gitee.com/linngc/central-mirror.git
git@gitee.com:linngc/central-mirror.git
linngc
central-mirror
central-mirror
4aaf4b1e930c

搜索帮助