我正在开发一个 web 服务器,
在顶部我有
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"
)
后来我有
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)
}
当我发出时我收到这个错误 go run CSServer
/CSServer.go:54: undefined: hmac.Equal
为什么?到底是怎么回事?为什么hmac.New很好,但hmac.Equals不是?
相关分类