You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
678 B
32 lines
678 B
package tools
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
func Token() string {
|
|
randString := fmt.Sprintf("%08v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000000))
|
|
return MD5(randString)
|
|
}
|
|
|
|
func GenerateGoodsHashSign() string {
|
|
randString := fmt.Sprintf("%08v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000000))
|
|
return MD5(randString)
|
|
}
|
|
|
|
func MD5(str string) string {
|
|
h := md5.New()
|
|
h.Write([]byte(str))
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
}
|
|
|
|
func SHA256Str(src string) string {
|
|
h := sha256.New()
|
|
h.Write([]byte(src)) // 需要加密的字符串为
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
} |