feat:完善信息
This commit is contained in:
@ -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]
|
||||
}
|
||||
|
Reference in New Issue
Block a user