jwcrypt

package
v0.0.0-...-5204ab8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 11 Imported by: 0

README

jwcrypt

-- import "github.com/cmcoffee/snugforge/jwcrypt"

Usage

func ParseRSAPrivateKey
func ParseRSAPrivateKey(keyData []byte, passphrase ...[]byte) (*rsa.PrivateKey, error)

ParseRSAPrivateKey auto-detects JWK (JSON) vs PEM/PKCS8 format and parses the RSA private key. Optional passphrase for encrypted PKCS8 keys.

func SignJWT
func SignJWT(alg JWTAlgorithm, key *rsa.PrivateKey, claims interface{}, headerFields ...map[string]string) (string, error)

SignJWT creates a signed JWT token (header.payload.signature) using the specified algorithm (RS256 or RS512). Claims can be map[string]interface{} or a struct. Optional headerFields adds custom JWT header fields (e.g. "kid", "type").

func SignRS256
func SignRS256(key *rsa.PrivateKey, claims interface{}, headerFields ...map[string]string) (string, error)

SignRS256 creates a signed JWT token using RS256 (RSA SHA-256).

func SignRS512
func SignRS512(key *rsa.PrivateKey, claims interface{}, headerFields ...map[string]string) (string, error)

SignRS512 creates a signed JWT token using RS512 (RSA SHA-512).

type JWK
type JWK struct {
	KeyType    string   `json:"kty"`
	Use        string   `json:"use,omitempty"`
	KeyOps     []string `json:"key_ops,omitempty"`
	Algorithm  string   `json:"alg,omitempty"`
	KeyID      string   `json:"kid,omitempty"`
	PrivateKey *rsa.PrivateKey
}

JWK represents a parsed JSON Web Key with all standard attributes (RFC 7517).

func ParseJWK
func ParseJWK(jwkData []byte) (*JWK, error)

ParseJWK parses a JWK (JSON Web Key) and returns a JWK struct with all standard attributes and the extracted RSA private key.

type JWTAlgorithm
type JWTAlgorithm string

JWT signing algorithm.

const (
	RS256 JWTAlgorithm = "RS256"
	RS512 JWTAlgorithm = "RS512"
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRSAPrivateKey

func ParseRSAPrivateKey(keyData []byte, passphrase ...[]byte) (*rsa.PrivateKey, error)

ParseRSAPrivateKey auto-detects JWK (JSON) vs PEM/PKCS8 format and parses the RSA private key. Optional passphrase for encrypted PKCS8 keys.

func SignJWT

func SignJWT(alg JWTAlgorithm, key *rsa.PrivateKey, claims interface{}, headerFields ...map[string]string) (string, error)

SignJWT creates a signed JWT token (header.payload.signature) using the specified algorithm (RS256 or RS512). Claims can be map[string]interface{} or a struct. Optional headerFields adds custom JWT header fields (e.g. "kid", "type").

func SignRS256

func SignRS256(key *rsa.PrivateKey, claims interface{}, headerFields ...map[string]string) (string, error)

SignRS256 creates a signed JWT token using RS256 (RSA SHA-256).

func SignRS512

func SignRS512(key *rsa.PrivateKey, claims interface{}, headerFields ...map[string]string) (string, error)

SignRS512 creates a signed JWT token using RS512 (RSA SHA-512).

Types

type JWK

type JWK struct {
	KeyType    string   `json:"kty"`
	Use        string   `json:"use,omitempty"`
	KeyOps     []string `json:"key_ops,omitempty"`
	Algorithm  string   `json:"alg,omitempty"`
	KeyID      string   `json:"kid,omitempty"`
	PrivateKey *rsa.PrivateKey
}

JWK represents a parsed JSON Web Key with all standard attributes (RFC 7517).

func ParseJWK

func ParseJWK(jwkData []byte) (*JWK, error)

ParseJWK parses a JWK (JSON Web Key) and returns a JWK struct with all standard attributes and the extracted RSA private key.

type JWTAlgorithm

type JWTAlgorithm string

JWT signing algorithm.

const (
	RS256 JWTAlgorithm = "RS256"
	RS512 JWTAlgorithm = "RS512"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL