Go has a tool for you to generate keys. Open Command Terminal and do the following:
> cd %GOROOT%\src\crypto\tls
> go run generate_cert.go --host localhost --ca true
//Substitua C:\ pelo local onde você quer que os arquivos fiquem
> move %GOROOT%\src\crypto\tls\cert.pem C:\cert.pem
> move %GOROOT%\src\crypto\tls\key.pem C:\key.pem
Now, in your go code, just do the following (I didn’t treat the errors to simplify the example):
//Substitua C:\ para o local onde estão os arquivos, caso você os tenha mudado de lugar
keyPEM, _ := ioutil.ReadFile("C:\key.pem")
privateKey, _ = jwt.ParseRSAPrivateKeyFromPEM(keyPEM)
certPEM, _ := ioutil.ReadFile("C:\cert.pem")
publicKey, _ = jwt.ParseRSAPublicKeyFromPEM(certPEM)
t := jwt.NewWithClaims(jwt.GetSigningMethod("RS256"), jwt.MapClaims{
//Suas Claims
})
signedToken, err := t.SignedString(signKey)
//Etc...
Recently I had a problem with how to generate rsa keys to be valid for validating with jwt. I got the result I wanted. Follow the project link. Heimdall
– Rafael G Firmino