golang hmac的sha1加密例子
发布时间:2020-12-16 18:11:23 所属栏目:大数据 来源:网络整理
导读:想要用go写btcchina平台的接口,api加密形式在php中是hash_ hmac('sha1',$string,$key); go中的一样有hmac包,下面是代码 package mainimport ("crypto/hmac""crypto/sha1""fmt""io")func main() {//sha1h := sha1.New()io.WriteString(h,"aaaaaa")fmt.Printf(
想要用go写btcchina平台的接口,api加密形式在php中是hash_hmac('sha1',$string,$key); go中的一样有hmac包,下面是代码 package main import ( "crypto/hmac" "crypto/sha1" "fmt" "io" ) func main() { //sha1 h := sha1.New() io.WriteString(h,"aaaaaa") fmt.Printf("%xn",h.Sum(nil)) //hmac,use sha1 key := []byte("123456") mac := hmac.New(sha1.New,key) mac.Write([]byte("aaaaaa")) fmt.Printf("%xn",mac.Sum(nil)) } 声明:此文系舞林cuzn(www.wulinlw.org)原创稿件,转载请保留版权 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |