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
|
func () { h := sha1.New() io.WriteString(h, strEncrypt) fmt.Printf("%xn", h.Sum(nil))
key := []byte("123456") mac := hmac.New(sha1.New, key) mac.Write([]byte("aaaaaa")) fmt.Printf("%xn", mac.Sum(nil)) }
func Md5(data string) string { md5 := md5.New() md5.Write([]byte(data)) md5Data := md5.Sum([]byte("")) return hex.EncodeToString(md5Data) }
func Hmac(key, data string) string { hmac := hmac.New(md5.New, []byte(key)) hmac.Write([]byte(data)) return hex.EncodeToString(hmac.Sum([]byte(""))) }
func Sha1(data string) string { sha1 := sha1.New() sha1.Write([]byte(data)) return hex.EncodeToString(sha1.Sum([]byte(""))) }
|
近期评论