douh9817 2013-08-15 21:21
浏览 158
已采纳

在此之前运行hmac.New时出现“ undefined:hmac.Equal”错误

I am developing a web server in go,
at the top I have

import ("net/http"
    "log"
    "fmt"
    "encoding/json"
    "encoding/hex"
    "time"
    "math/rand"
    "crypto/sha256"
    "crypto/hmac"
    "strconv"
    "strings"
    "github.com/crowdmob/goamz/aws"
    "github.com/crowdmob/goamz/dynamodb"
)

later I have

func singSomething(someid string) string {
mac := hmac.New(sha256.New, key)
    mac.Write([]byte(id))
    b := mac.Sum(nil)
return hex.EncodeToString(b)
}

func validateSignature(id, signature string) bool {
mac := hmac.New(sha256.New, key)
    mac.Write([]byte(id))
    expectedMAC := mac.Sum(nil)
    signatureMAC, err := hex.DecodeString(signature)
    if err != nil {
    fmt.Println("PROBLEM IN DECODING HUH!")
    return false
    }
return hmac.Equal(expectedMAC,signatureMAC)

}

I get this error when I issue go run CSServer
/CSServer.go:54: undefined: hmac.Equal

Why? What is going on? How come hmac.New is fine but hmac.Equals is not?

  • 写回答

2条回答 默认 最新

  • dskvfdxgdo2422392 2013-08-16 00:44
    关注

    Don't know what the problem was,
    but after striping down the code and puting it in play.golang.org and seeing that it works fine there bun not on my machine, I checked and the my version, it was go1.0.3 I installed the latest go1.1.2 darwin/amd64 and problem solved, very weird.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题