github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/infrastructure/token/rs256.go (about) 1 package token 2 3 import ( 4 jwt "github.com/dgrijalva/jwt-go" 5 ) 6 7 type RS256Generator struct { 8 algorithm jwt.SigningMethod 9 } 10 11 func NewRS256() RS256Generator { 12 return RS256Generator{ 13 algorithm: jwt.SigningMethodRS256, 14 } 15 } 16 17 //SignRS256 Sign payload with asymmetric algorithm RSA Signature with SHA-256 18 func (j RS256Generator) Sign(payload interface{}, privateKey []byte) (string, error) { 19 20 claims := createClaims(payload) 21 22 signKey, _ := jwt.ParseRSAPrivateKeyFromPEM(privateKey) 23 24 token := jwt.NewWithClaims(j.algorithm, claims) 25 26 return token.SignedString(signKey) 27 }