https://help.aliyun.com/document_detail/25492.html?spm=5176.doc25490.2.2.Uwn9UA
我按照url的文档,对StringToSign进行hmac sha1进行加密,然后base64,得到的结果与文档例子的结果不一致
[v2-c7765a6260196517ed843e4f01d9e381_r.png](http://studygolang.qiniudn.com/170504/f396c10be7d70db4cbf999e6d0680f74.png)
我的代码:
```
package main
import "fmt"
import "crypto/sha1"
import "crypto/hmac"
import b64 "encoding/base64"
func main() {
key := []byte("testsecret&")
mac := hmac.New(sha1.New, key)
mac.Write([]byte("GET&%2F&AccessKeyId%3Dtestid&Action%3DDescribeRegions&Format%3DXML&SignatureMethod%3DHMAC-SHA1&SignatureNonce%3D3ee8c1b8-83d3-44af-a94f-4e0ad82fd6cf&SignatureVersion%3D1.0&TimeStamp%3D2016-02-23T12%253A46%253A24Z&Version%3D2014-05-26"))
s := b64.StdEncoding.EncodeToString(mac.Sum(nil))
fmt.Println(s)
}
```
输出的结果:LZ5DVzNj95387UDL70u7+18AwWY= 与官网文档结果不一致,搞了一天了,不知道啥原因!
有疑问加站长微信联系(非本文作者)