function.go 622 字节
Newer Older
E
V2.0.0  
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package utils
import (
	"encoding/hex"
	"time"
	"crypto/md5"	
	"math/rand"
)

func Md5(encodeString string) string{
	h := md5.New()
    h.Write([]byte(encodeString)) 
    return hex.EncodeToString(h.Sum(nil)) // 输出加密结果
}


//生成随机字符串
func  GetRandomString(num int) string {  
    str := "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"  
    bytes := []byte(str)  
    result := []byte{}  
    r := rand.New(rand.NewSource(time.Now().UnixNano()))  
    for i := 0; i < num; i++ {  
        result = append(result, bytes[r.Intn(len(bytes))])  
    }  
    return string(result)  
}