添加文件: server_tb_LinkedMall/pkg/crypto/crypto.go
This commit is contained in:
parent
a86caac18f
commit
ab7905ede2
|
|
@ -0,0 +1,25 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GenerateNonce 生成随机字符串,用于防重放
|
||||
func GenerateNonce() string {
|
||||
buf := make([]byte, 16)
|
||||
_, _ = rand.Read(buf)
|
||||
return hex.EncodeToString(buf)
|
||||
}
|
||||
|
||||
// GenerateTimestamp 生成当前时间戳(毫秒)
|
||||
func GenerateTimestamp() int64 {
|
||||
return time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
// FormatTimestamp 格式化时间戳为字符串
|
||||
func FormatTimestamp(ts int64) string {
|
||||
return fmt.Sprintf("%d", ts)
|
||||
}
|
||||
Loading…
Reference in New Issue