key is invalid #256
Comments
Hopefully the author can chime in with a more detailed answer, though I had to use Go to generate my keys. I will edit this later today and post the code that I used if I can find it, unless the issue is solved. Edit: The code that I used was from here: You may want to modify the |
The RSA signing methods require a
See the required key types in the README or the documentation. |
Also, I believe the (in progress) 4.0 version of the library will update the error to more accurately state whether the key is invalid or the key type. |
@dgrijalva Thanks for your help this (*rsa.PrivateKey) was the missing link error message wasn't clear enough. I used https://gist.github.com/sdorra/1c95de8cb80da31610d2ad767cd6f251 to generate private and public keys and then modified this bit from the code above. var (
verifyKey *rsa.PublicKey
signKey *rsa.PrivateKey
)
// Read the key files before starting http handlers
func initKeys() {
var err error
signKeyByte, err := ioutil.ReadFile(privKeyPath)
signKey, err = jwt.ParseRSAPrivateKeyFromPEM(signKeyByte)
if err != nil {
log.Fatalf("[initKeys]: %s\n", err)
}
verifyKeyByte, err := ioutil.ReadFile(pubKeyPath)
verifyKey, err = jwt.ParseRSAPublicKeyFromPEM(verifyKeyByte)
if err != nil {
log.Fatalf("[initKeys]: %s\n", err)
panic(err)
}
} |
Just in case you need an example, this code works:
|
I generated private and public keys using
openssl genrsa -out keys/app.rsa 2048 && openssl rsa -in keys/app.rsa -outform PEM -pubout -out keys/app.rsa.pub
Then when I tried to generate jwt token with code below I get key invalid.
As you can see from the above signKey is of type []byte I don't know what is wrong with the code above please help me figure out what is wrong just learning go.
The text was updated successfully, but these errors were encountered: