duanjianqu3685 2017-12-13 04:33
浏览 34
已采纳

为什么我的hmac密钥关闭了?

I am trying to generate an hmac key for use in an image proxy. I have:

https://play.golang.org/p/fec_N2Nim4

package main

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/base64"
    "fmt"
)

func main() {
    mac := hmac.New(sha256.New, []byte("secret key"))
        mac.Write([]byte("https://octodex.github.com/images/codercat.jpg"))
        want := mac.Sum(nil)
        fmt.Println("result: ",base64.URLEncoding.EncodeToString(want)) // expect "sXyMwWKIC5JPCtlYOQ2f4yMBTqpjtUsfI67Sp7huXIYY="
}

This is based off the package's recommended formula for generating the key as well as other methods I have tried, which all result in the same key. The url given in the example, however, has an "s" prepended to the front:

http://localhost:8080/500,sXyMwWKIC5JPCtlYOQ2f4yMBTqpjtUsfI67Sp7huXIYY=/https://octodex.github.com/images/codercat.jpg

vs what I am getting:

http://localhost:8080/500,XyMwWKIC5JPCtlYOQ2f4yMBTqpjtUsfI67Sp7huXIYY=/https://octodex.github.com/images/codercat.jpg
  • 写回答

1条回答 默认 最新

  • dongyi2006 2017-12-13 06:00
    关注

    As per the docs of the given library, the key format is as below:

    s{signature}
    

    Please check the docs at Url signing signature

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看