feat:完善信息

This commit is contained in:
henry
2021-10-09 11:55:54 +08:00
parent 2191f0ea3f
commit af44287b4a
19 changed files with 368 additions and 12 deletions

View File

@ -6,11 +6,15 @@ import (
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"github.com/speps/go-hashids"
"strings"
"golang.org/x/crypto/bcrypt"
)
// salt 盐值
const salt = "CHeF6AC392"
// Md5String
func Md5String(s string, salt ...string) string {
h := md5.New()
@ -50,3 +54,22 @@ func HashString(s []byte) string {
func HashCompare(src, compare []byte) bool {
return bcrypt.CompareHashAndPassword(src, compare) == nil
}
// HASHIDEncode 混淆
func HASHIDEncode(src int) string {
hd := hashids.NewData()
hd.Salt = salt
hd.MinLength = 6
h := hashids.NewWithData(hd)
e, _ := h.Encode([]int{src})
return e
}
// HASHIDDecode 还原混淆
func HASHIDDecode(src string) int {
hd := hashids.NewData()
hd.Salt = salt
h := hashids.NewWithData(hd)
e, _ := h.DecodeWithError(src)
return e[0]
}