我正在 GoLang API 中設(shè)置安全中間件,似乎所有設(shè)置都正確,但我收到錯(cuò)誤“密鑰類型無(wú)效”。我已確認(rèn)我的簽名算法是 RS256 并且中間件選項(xiàng)已配置 @SigningMethod: jwt.SigningMethodRS256我有一個(gè)有效的令牌……中間件中的其他所有內(nèi)容都會(huì)通過(guò)。中間件中此錯(cuò)誤的入口點(diǎn)是 jwt.ParseRSAPrivateKeyFromPEM 方法。我已將錯(cuò)誤隔離在包 github.com/dgrijalva/jwt-go/rsa.go 中,Verify() on line :62 是拋出的 ErrInvalidKeyType。到目前為止,所有參數(shù)似乎都是可靠且適當(dāng)?shù)模ɡ?m|signingString|signature|key),但是這個(gè) key.(*rsa.PublicKey) 失敗了......在我的調(diào)試器(GoLand)中,我檢查 *rsa 并得到響應(yīng)“找不到 rsa 的符號(hào)值”...if rsaKey, ok = key.(*rsa.PublicKey); !ok {
return ErrInvalidKeyType
}請(qǐng)注意……如果還不是太明顯的話……我對(duì) GoLang 很菜鳥(niǎo)- - - 更新 - - -因此,在最細(xì)粒度的級(jí)別上,恐慌從 go/1.12.8/libexec/src/crypto/rsa/rsa.go:49 開(kāi)始func (pub *PublicKey) Size() int {
log.Printf("SIZE ::: %v :: %v",pub.N.BitLen(), pub.N)
return (pub.N.BitLen() + 7) / 8
}pub 被視為零指針取消引用。我追溯到 mux -->加密/rsa.VerifyPKCS1v15(...) /usr/local/Cellar/go/1.12.8/libexec/src/crypto/rsa/pkcs1v15.go:275github.com/dgrijalva/jwt-go.(*SigningMethodRSA).Verify(...) /Users/me/Sandbox/src/github.com/dgrijalva/jwt-go/rsa.go:73github.com/dgrijalva/jwt-go.(*Parser).ParseWithClaims(...) /Users/me/Sandbox/src/github.com/dgrijalva/jwt-go/parser.go:77github.com/dgrijalva/jwt-go.(*Parser).Parse(...) /Users/btschirhart/Sandbox/src/github.com/dgrijalva/jwt-go/parser.go:20github.com/dgrijalva/jwt-go.Parse(...) /Users/me/Sandbox/src/github.com/dgrijalva/jwt-go/token.go:89github.com/auth0/go-jwt-middleware.(*JWTMiddleware).CheckJWT(...) /Users/me/Sandbox/src/github.com/auth0/go-jwt-middleware/jwtmiddleware.go:203github.com/auth0/go-jwt-middleware.(*JWTMiddleware).Handler.func1(...) /Users/me/Sandbox/src/github.com/auth0/go-jwt-middleware/jwtmiddleware.go:110net/http.HandlerFunc.ServeHTTP(...) /usr/local/Cellar/go/1.12.8/libexec/src/net/http/server.go:1995github.com/gorilla/mux.(*Router).ServeHTTP(...) /Users/me/Sandbox/src/github.com/gorilla/mux/mux.go:210 +0xe3
在 jwt-go 中解析 JWT Auth 令牌時(shí),密鑰的類型無(wú)效
喵喵時(shí)光機(jī)
2023-07-17 09:50:52