Convert Figma logo to code with AI

square logogo-jose

An implementation of JOSE standards (JWE, JWS, JWT) in Go

1,966
275
1,966
0

Top Related Projects

10,803

ARCHIVE - Golang implementation of JSON Web Tokens (JWT). This project is now maintained at:

2,126

Complete implementation of JWx (Javascript Object Signing and Encryption/JOSE) technologies for Go. #golang #jwt #jws #jwk #jwe

Quick Overview

The go-jose library is a comprehensive implementation of the JOSE (JSON Object Signing and Encryption) standards in Go. It provides a set of tools for working with JSON Web Tokens (JWT), JSON Web Signatures (JWS), and JSON Web Encryption (JWE), making it easier to integrate these security features into Go-based applications.

Pros

  • Comprehensive JOSE Support: The library covers a wide range of JOSE-related functionality, including signing, verification, encryption, and decryption.
  • Flexibility: The library is designed to be flexible and extensible, allowing developers to customize the behavior to fit their specific needs.
  • Cryptographic Primitives: The library provides a set of cryptographic primitives, such as RSA, ECDSA, and HMAC, which can be used independently of the JOSE-specific functionality.
  • Actively Maintained: The project is actively maintained, with regular updates and bug fixes.

Cons

  • Complexity: The library can be complex to use, especially for developers who are new to JOSE and cryptographic concepts.
  • Performance: Depending on the specific use case, the library may not be the most performant option, as it prioritizes flexibility and extensibility over raw speed.
  • Limited Documentation: The documentation for the library could be more comprehensive, making it harder for new users to get started.
  • Dependency on External Libraries: The library relies on several external dependencies, which can increase the overall complexity of the project.

Code Examples

Here are a few examples of how to use the go-jose library:

  1. Signing a JWT:
import (
    "fmt"
    "time"

    "github.com/square/go-jose/v3"
    "github.com/square/go-jose/v3/jwt"
)

func main() {
    // Create a new signer
    signer, err := jose.NewSigner(jose.SigningKey{
        Algorithm: jose.HS256,
        Key:       []byte("secret"),
    }, (&jose.SignerOptions{}).WithType("JWT"))
    if err != nil {
        panic(err)
    }

    // Create a new JWT claims set
    claims := jwt.Claims{
        Subject:   "subject",
        Issuer:    "issuer",
        Expiration: jwt.NewNumericDate(time.Now().Add(time.Hour * 24)),
    }

    // Sign the JWT
    token, err := jwt.Signed(signer).Claims(claims).CompactSerialize()
    if err != nil {
        panic(err)
    }

    fmt.Println(token)
}
  1. Verifying a JWT:
import (
    "fmt"

    "github.com/square/go-jose/v3/jwt"
)

func main() {
    // Parse the JWT token
    token, err := jwt.ParseSigned("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0IiwiaXNzIjoiaXNzdWVyIiwiZXhwIjoxNjE4NDg4MDAwfQ.Nh-Iq-Ks3Ej-Ks3Ej-Ks3Ej-Ks3Ej-Ks3Ej-Ks3Ej")
    if err != nil {
        panic(err)
    }

    // Verify the JWT token
    var claims jwt.Claims
    if err := token.Claims([]byte("secret"), &claims); err != nil {
        panic(err)
    }

    fmt.Printf("Subject: %s\nIssuer: %s\nExpiration: %s\n", claims.Subject, claims.Issuer, claims.Expiration)
}
  1. Encrypting a message:
import (
    "fmt"

    "github.com/square/go-jose/v3"
)

func main() {
    // Create a new enc

Competitor Comparisons

10,803

ARCHIVE - Golang implementation of JSON Web Tokens (JWT). This project is now maintained at:

Pros of jwt-go

  • Focused specifically on JSON Web Tokens (JWTs), making it simpler for JWT-specific use cases
  • Lightweight and easy to use, with a straightforward API
  • Well-established in the Go community with a large user base

Cons of jwt-go

  • Limited to JWT functionality, lacking support for other JOSE standards
  • Less actively maintained, with fewer recent updates compared to go-jose
  • May have some security vulnerabilities that require careful usage

Code Comparison

jwt-go:

token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
    "foo": "bar",
    "exp": time.Now().Add(time.Hour * 72).Unix(),
})
tokenString, err := token.SignedString(mySigningKey)

go-jose:

signer, err := jose.NewSigner(jose.SigningKey{Algorithm: jose.HS256, Key: mySigningKey}, nil)
payload := []byte(`{"foo":"bar"}`)
object, err := signer.Sign(payload)
tokenString, err := object.CompactSerialize()

go-jose offers a more comprehensive implementation of JOSE standards, including JWE, JWS, and JWT. It provides more flexibility and features but may have a steeper learning curve. jwt-go, on the other hand, is more focused and easier to use for simple JWT operations but lacks the broader JOSE support.

2,126

Complete implementation of JWx (Javascript Object Signing and Encryption/JOSE) technologies for Go. #golang #jwt #jws #jwk #jwe

Pros of jwx

  • More comprehensive support for JWS, JWE, JWK, and JWT
  • Better performance in some operations, especially for large payloads
  • More actively maintained with frequent updates and improvements

Cons of jwx

  • Steeper learning curve due to more extensive API
  • Less widespread adoption compared to go-jose

Code Comparison

jwx:

key, err := jwk.ParseKey([]byte(jwkJSON))
token, err := jwt.Sign(payload, jwt.WithKey(jwa.RS256, key))

go-jose:

signer, err := jose.NewSigner(jose.SigningKey{Algorithm: jose.RS256, Key: privateKey}, nil)
token, err := signer.Sign([]byte(payload))

Summary

Both jwx and go-jose are popular libraries for working with JSON Web Tokens (JWT) in Go. jwx offers more comprehensive features and better performance for some operations, while go-jose has a simpler API and wider adoption. The choice between the two depends on specific project requirements, performance needs, and developer preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Go JOSE v1/v2 (DEPRECATED)

This repository is DEPRECATED.

It will be placed in an archived state on February 27th, 2023.

What should I use instead?

Development of Go JOSE has continued in a new organization:

https://github.com/go-jose/go-jose

We strongly encourage users of square/go-jose to migrate to v3 of go-jose/go-jose. No support, security fixes or updates will be delivered to the v1/v2 branches in the Square repository.