目录
- 一、MD5加解密
- 二、HmacSHA256加解密
- 三、获取uuid、时间戳
一、MD5加解密
import ("crypto/md5""encoding/hex"
)func md5Encrypt(txt string) string {m5 := md5.New()m5.Write([]byte(txt))txtHash := hex.EncodeToString(m5.Sum(nil))return txtHash
}
二、HmacSHA256加解密
import ("crypto/hmac""crypto/sha256""encoding/base64"
)func HmacSha256ToBase64(key string, data string) string {mac := hmac.New(sha256.New, []byte(key))_, _ = mac.Write([]byte(data))encode := mac.Sum(nil)return base64.StdEncoding.EncodeToString(encode)
}
三、获取uuid、时间戳
import ("github.com/google/uuid""strconv""time"
)
func main() {now := time.Now()time_1 := strconv.FormatInt(now.Unix(), 10) time_2 := strconv.FormatInt(now.UnixMilli(), 10) println(time_1)println(time_2)println(uuid.New().String())
}