Go语言HmacSHA1

Go语言HmacSHA1

对比 http://www.metools.info/code/c25.html

package main

import (
    "crypto/hmac"
    "crypto/sha1"
    "encoding/hex"
    "fmt"
)

func HmacSHA1(key string, data string) string {
    mac := hmac.New(sha1.New, []byte(key))
    mac.Write([]byte(data))
    return hex.EncodeToString(mac.Sum(nil))
}

func main() {
    data := HmacSHA1("123", "7848871513115BC19322112B3")
    fmt.Printf("%v", data)
}

 

posted @ 2020-02-18 17:42  菩提树~今生  阅读(2469)  评论(0编辑  收藏  举报