func getPrivateKey() *rsa.PrivateKey { privateKeyFile, err := os.Open(settings.Get().PrivateKeyPath) if err != nil { panic(err) } pemfileinfo, _ := privateKeyFile.Stat() var size int64 = pemfileinfo.Size() pembytes := make([]byte, size) buffer := bufio.NewReader(privateKeyFile) _, err = buffer.Read(pembytes) data, _ := pem.Decode([]byte(pembytes)) privateKeyFile.Close() privateKeyImported, err := x509.ParsePKCS1PrivateKey(data.Bytes) if err != nil { panic(err) } return privateKeyImported }
func getPrivateKey() *rsa.PrivateKey { fmt.Println(settings.Get().PrivateKeyPath) privateKeyFile, err := os.Open("security/settings/keys/private_key") ///Users/amosunsunday/Documents/Official/xtremepay/Sources/services/src/xtremepay.com/backoffice/security/settings/ if err != nil { panic(err) } pemfileinfo, _ := privateKeyFile.Stat() var size int64 = pemfileinfo.Size() pembytes := make([]byte, size) buffer := bufio.NewReader(privateKeyFile) _, err = buffer.Read(pembytes) data, _ := pem.Decode([]byte(pembytes)) privateKeyFile.Close() privateKeyImported, err := x509.ParsePKCS1PrivateKey(data.Bytes) if err != nil { panic(err) } return privateKeyImported }
func getPublicKey() *rsa.PublicKey { publicKeyFile, err := os.Open(settings.Get().PublicKeyPath) if err != nil { panic(err) } pemfileinfo, _ := publicKeyFile.Stat() var size int64 = pemfileinfo.Size() pembytes := make([]byte, size) buffer := bufio.NewReader(publicKeyFile) _, err = buffer.Read(pembytes) data, _ := pem.Decode([]byte(pembytes)) publicKeyFile.Close() publicKeyImported, err := x509.ParsePKIXPublicKey(data.Bytes) if err != nil { panic(err) } rsaPub, ok := publicKeyImported.(*rsa.PublicKey) if !ok { panic(err) } return rsaPub }
// GenerateToken ... func (backend *JWTAuthenticationBackend) GenerateToken(userUUID string) (string, error) { token := jwt.New(jwt.SigningMethodRS512) token.Claims["exp"] = time.Now().Add(time.Hour * time.Duration(settings.Get().JWTExpirationDelta)).Unix() token.Claims["iat"] = time.Now().Unix() token.Claims["sub"] = userUUID tokenString, err := token.SignedString(backend.privateKey) if err != nil { panic(err) return "", err } return tokenString, nil }