I'm using this example, however it is slightly outdated. So, for, example SignedString(key)
, I guess, receives *rsa.PublicKey
instead of []byte
in case of RS256 signing method. I generated my private key using
openssl genrsa -out key.rsa 1024
And now trying to parse it:
package main
import (
"fmt"
"github.com/dgrijalva/jwt-go"
)
func main() {
pem := []byte(`-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCycI9LZT8qM/zCGH0CNxAi7gy7w1YjqZN1N8yFfbmv9toVC82S
bZDv8NVYVlFNhUbtUFg77TYhHmyPpr4hKqvPrVc0rqVFe4ggQYdXovDgLZhO1MxB
i4vw9tLRlAK8TYNFqaFiX6lFgRp8trd01GFhkBJMzZCMmBQFkcEgWqT6MQIDAQAB
AoGBAKSru5GYnfIUh+2XK8YfioSxqo6cdaHznGFQXS3UGMiKxjcl7VB0TI0hc8FR
5zXjCNF4k/S5tHpb2VO4TT3OYz55/JEOGAXvIMW2UYtL4TwR3+46TRJ95KKowq+c
3JndjmGjUbvWawtbNklkmgoEkLI8wYu9yss9293GBnff14ABAkEA1scxu0svrIZ1
R5YmpXOfrtGwsjbdowGNxZTedWlbJukBSNPSIpuUvkzF2PXlPBS80p5yxbYlp1gg
UhsfXWJwIQJBANSv7lEuHV0QnVVoYVtNijwEHIi7iG7xu7hDQ7bK/kwWV6wqnvfP
PZopZPDXCRlnxbubo0/RJz4LsaJflDJKiBECQC/3FFgrll4FOTPfiInypHq6QafL
MPwyYKL7eCLogH7UEoFdLNSlwjYtlxG4+JTOXMz8rc0RvJ7+w1kSzZJhZYECQHMU
DhqWnQSx7K89nw/L0LPQda/16Eg/O5bjrkvFYfrBTAa3uPPUijxTkW5Oq3m3kGGG
QML7JASKRz7YAFOFyEECQQCUBNONRYMMzzr4llGOcKISXJtewlOPTHGP++OiHWMB
rPzZDyi5ONNgySF8t/QnJMTRpRQ5axi0UhojL/OzUt/w
-----END RSA PRIVATE KEY-----`)
key, err := jwt.ParseRSAPublicKeyFromPEM(pem)
fmt.Println(key, err)
}
But I get asn1: structure error: tags don't match (16 vs {class:0 tag:2 length:1 isCompound:false}) {optional:false explicit:false application:false defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} tbsCertificate @2
in response.
Is my key generating command somehow wrong? What should I read to be able to debug this? What asn1 has to do with it? Key has some particular syntax?