想要用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("%x\n",h.Sum(nil)) //hmac,use sha1 key := []byte("123456") mac := hmac.New(sha1.New,key) mac.Write([]byte("aaaaaa")) fmt.Printf("%x\n",mac.Sum(nil)) }
声明:此文系舞林cuzn(www.wulinlw.org)原创稿件,转载请保留版权