📚 go-jose - Awesome Go Library for Authentication and OAuth

Go Gopher mascot for go-jose

Fairly complete implementation of the JOSE working group's JSON Web Token, JSON Web Signatures, and JSON Web Encryption specs.

🏷️ Authentication and OAuth
📂 Libraries for implementing authentication schemes.
318 stars
View on GitHub 🔗

Detailed Description of go-jose

Go JOSE

godoc godoc license test

Package jose aims to provide an implementation of the Javascript Object Signing and Encryption set of standards. This includes support for JSON Web Encryption, JSON Web Signature, and JSON Web Token standards.

Overview

The implementation follows the JSON Web Encryption (RFC 7516), JSON Web Signature (RFC 7515), and JSON Web Token (RFC 7519) specifications. Tables of supported algorithms are shown below. The library supports both the compact and JWS/JWE JSON Serialization formats, and has optional support for multiple recipients. It also comes with a small command-line utility (jose-util) for dealing with JOSE messages in a shell.

Note: We use a forked version of the encoding/json package from the Go standard library which uses case-sensitive matching for member names (instead of case-insensitive matching). This is to avoid differences in interpretation of messages between go-jose and libraries in other languages.

Versions

Version 4 (branch, doc, releases) is the current stable version:

import "github.com/go-jose/go-jose/v4"

The old square/go-jose repo contains the prior v1 and v2 versions, which are still useable but not actively developed anymore.

Version 3, in this repo, is still receiving security fixes but not functionality updates.

Supported algorithms

See below for a table of supported algorithms. Algorithm identifiers match the names in the JSON Web Algorithms standard where possible. The Godoc reference has a list of constants.

Key encryptionAlgorithm identifier(s)
RSA-PKCS#1v1.5RSA1_5
RSA-OAEPRSA-OAEP, RSA-OAEP-256
AES key wrapA128KW, A192KW, A256KW
AES-GCM key wrapA128GCMKW, A192GCMKW, A256GCMKW
ECDH-ES + AES key wrapECDH-ES+A128KW, ECDH-ES+A192KW, ECDH-ES+A256KW
ECDH-ES (direct)ECDH-ES1
Direct encryptiondir1

1. Not supported in multi-recipient mode

Signing / MACAlgorithm identifier(s)
RSASSA-PKCS#1v1.5RS256, RS384, RS512
RSASSA-PSSPS256, PS384, PS512
HMACHS256, HS384, HS512
ECDSAES256, ES384, ES512
Ed25519EdDSA2

2. Only available in version 2 of the package

Content encryptionAlgorithm identifier(s)
AES-CBC+HMACA128CBC-HS256, A192CBC-HS384, A256CBC-HS512
AES-GCMA128GCM, A192GCM, A256GCM
CompressionAlgorithm identifiers(s)
DEFLATE (RFC 1951)DEF

Supported key types

See below for a table of supported key types. These are understood by the library, and can be passed to corresponding functions such as NewEncrypter or NewSigner. Each of these keys can also be wrapped in a JWK if desired, which allows attaching a key id.

Algorithm(s)Corresponding types
RSA*rsa.PublicKey, *rsa.PrivateKey
ECDH, ECDSA*ecdsa.PublicKey, *ecdsa.PrivateKey
EdDSA1ed25519.PublicKey, ed25519.PrivateKey
AES, HMAC[]byte

1. Only available in version 2 or later of the package

Examples

godoc godoc

Examples can be found in the Godoc reference for this package. The jose-util subdirectory also contains a small command-line utility which might be useful as an example as well.