-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
40 lines (34 loc) · 798 Bytes
/
utils.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils
import (
"crypto/hmac"
"crypto/md5"
"crypto/rand"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"math/big"
"strconv"
"time"
)
//GetMD5Hash generates md5
func GetMD5Hash(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}
func GetNonce() string {
result, _ := rand.Int(rand.Reader, big.NewInt(100000000))
return result.String()
}
func GetTimeStamp() string {
m := time.Now().UnixNano() / int64(time.Millisecond)
return strconv.FormatInt(m, 10)
}
func HmacSHA1Encrypt(accessSecretKey, encryptText string) []byte {
key := []byte(accessSecretKey)
mac := hmac.New(sha1.New, key)
mac.Write([]byte(encryptText))
return mac.Sum(nil)
}
func Base64Encode(binput []byte) string {
return base64.StdEncoding.EncodeToString(binput)
}