dgrijalva / jwt-go

ARCHIVE - Golang implementation of JSON Web Tokens (JWT). This project is now maintained at:
https://github.com/golang-jwt/jwt
MIT License
10.78k stars 997 forks source link

Example of how to create RSA keys for use with jwt.ParseRSAPrivateKeyFromPEM #443

Closed digitalhurricane-io closed 3 years ago

digitalhurricane-io commented 3 years ago

I think it would be nice if an example of how to generate keys was added in the docs. I don't see any other people having issues so maybe I'm the only one that needs the documentation :)

But I keep getting errors like: asn1: structure error: tags don't match (2 vs {class:0 tag:16 length:13 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue: tag: stringType:0 timeType:0 set:false omitEmpty:false} int @2

I'm creating keys with openssl like this: openssl genrsa -out private_key.pem 4096 openssl rsa -pubout -in private_key.pem -out public_key.pem

The opening and closing tags of my private key looks like: -----BEGIN RSA PRIVATE KEY----- ..... -----END RSA PRIVATE KEY-----

I'm using go 1.15 and version v3.2.0 of this library

Thanks

digitalhurricane-io commented 3 years ago

I was trying to use jwt.ParseRSAPrivateKeyFromPEM on the public key instead of the private key. Can't believe I spent so much time debugging this. Closing this issue.