Documentation ¶
Index ¶
- Constants
- Variables
- func Decrypt(prompt string, data []byte, opts ...Option) ([]byte, error)
- func IsAsymmetric(k *JSONWebKey) bool
- func IsSymmetric(k *JSONWebKey) bool
- func ParseKeySet(filename string, opts ...Option) (*jose.JSONWebKey, error)
- func ReadJWKSet(filename string) ([]byte, error)
- func TrimPrefix(err error) error
- func ValidateJWK(jwk *JSONWebKey) error
- type Audience
- type Builder
- type Claims
- type ContentEncryption
- type ContentType
- type Encrypter
- type EncrypterOptions
- type Expected
- type JSONWebEncryption
- type JSONWebKey
- type JSONWebKeySet
- type JSONWebSignature
- type JSONWebToken
- type KeyAlgorithm
- type NumericDate
- type Option
- type Recipient
- type SignatureAlgorithm
- type Signer
- type SignerOptions
- type SigningKey
Constants ¶
const ( RSA1_5 = KeyAlgorithm("RSA1_5") // RSA-PKCS1v1.5 RSA_OAEP = KeyAlgorithm("RSA-OAEP") // RSA-OAEP-SHA1 RSA_OAEP_256 = KeyAlgorithm("RSA-OAEP-256") // RSA-OAEP-SHA256 A128KW = KeyAlgorithm("A128KW") // AES key wrap (128) A192KW = KeyAlgorithm("A192KW") // AES key wrap (192) A256KW = KeyAlgorithm("A256KW") // AES key wrap (256) DIRECT = KeyAlgorithm("dir") // Direct encryption ECDH_ES = KeyAlgorithm("ECDH-ES") // ECDH-ES ECDH_ES_A128KW = KeyAlgorithm("ECDH-ES+A128KW") // ECDH-ES + AES key wrap (128) ECDH_ES_A192KW = KeyAlgorithm("ECDH-ES+A192KW") // ECDH-ES + AES key wrap (192) ECDH_ES_A256KW = KeyAlgorithm("ECDH-ES+A256KW") // ECDH-ES + AES key wrap (256) A128GCMKW = KeyAlgorithm("A128GCMKW") // AES-GCM key wrap (128) A192GCMKW = KeyAlgorithm("A192GCMKW") // AES-GCM key wrap (192) A256GCMKW = KeyAlgorithm("A256GCMKW") // AES-GCM key wrap (256) PBES2_HS256_A128KW = KeyAlgorithm("PBES2-HS256+A128KW") // PBES2 + HMAC-SHA256 + AES key wrap (128) PBES2_HS384_A192KW = KeyAlgorithm("PBES2-HS384+A192KW") // PBES2 + HMAC-SHA384 + AES key wrap (192) PBES2_HS512_A256KW = KeyAlgorithm("PBES2-HS512+A256KW") // PBES2 + HMAC-SHA512 + AES key wrap (256) )
Key management algorithms
const ( HS256 = "HS256" // HMAC using SHA-256 HS384 = "HS384" // HMAC using SHA-384 HS512 = "HS512" // HMAC using SHA-512 RS256 = "RS256" // RSASSA-PKCS-v1.5 using SHA-256 RS384 = "RS384" // RSASSA-PKCS-v1.5 using SHA-384 RS512 = "RS512" // RSASSA-PKCS-v1.5 using SHA-512 ES256 = "ES256" // ECDSA using P-256 and SHA-256 ES384 = "ES384" // ECDSA using P-384 and SHA-384 ES512 = "ES512" // ECDSA using P-521 and SHA-512 PS256 = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256 PS384 = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384 PS512 = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512 EdDSA = "EdDSA" // Ed25591 )
Signature algorithms
const ( A128CBC_HS256 = ContentEncryption("A128CBC-HS256") // AES-CBC + HMAC-SHA256 (128) A192CBC_HS384 = ContentEncryption("A192CBC-HS384") // AES-CBC + HMAC-SHA384 (192) A256CBC_HS512 = ContentEncryption("A256CBC-HS512") // AES-CBC + HMAC-SHA512 (256) A128GCM = ContentEncryption("A128GCM") // AES-GCM (128) A192GCM = ContentEncryption("A192GCM") // AES-GCM (192) A256GCM = ContentEncryption("A256GCM") // AES-GCM (256) )
Content encryption algorithms
const ( P256 = "P-256" // P-256 curve (FIPS 186-3) P384 = "P-384" // P-384 curve (FIPS 186-3) P521 = "P-521" // P-521 curve (FIPS 186-3) )
Elliptic curves
const ( // Key management algorithms DefaultECKeyAlgorithm = ECDH_ES DefaultRSAKeyAlgorithm = RSA_OAEP_256 DefaultOctKeyAlgorithm = A256GCMKW // Signature algorithms DefaultRSASigAlgorithm = RS256 DefaultOctSigsAlgorithm = HS256 // Content encryption algorithm DefaultEncAlgorithm = A256GCM )
Default key management, signature, and content encryption algorithms to use if none is specified.
const ( DefaultRSASize = 2048 DefaultOctSize = 32 )
Default sizes
const Ed25519 = "Ed25519"
Ed25519 is the EdDSA signature scheme using SHA-512/256 and Curve25519
const MaxDecryptTries = 3
MaxDecryptTries is the maximum number of attempts to decrypt a file.
const SupportsPBKDF2 = true
SupportsPBKDF2 constant to know if the underlaying library supports password based cryptography algorithms.
Variables ¶
var ErrCryptoFailure = jose.ErrCryptoFailure
ErrCryptoFailure indicates an error in a cryptographic primitive.
var ErrExpired = jwt.ErrExpired
ErrExpired indicates that token is used after expiry time indicated in exp claim.
var ErrInvalidAudience = jwt.ErrInvalidAudience
ErrInvalidAudience indicated invalid aud claim.
var ErrInvalidID = jwt.ErrInvalidID
ErrInvalidID indicates invalid jti claim.
var ErrInvalidIssuer = jwt.ErrInvalidIssuer
ErrInvalidIssuer indicates invalid iss claim.
var ErrInvalidSubject = jwt.ErrInvalidSubject
ErrInvalidSubject indicates invalid sub claim.
var ErrNotValidYet = jwt.ErrNotValidYet
ErrNotValidYet indicates that token is used before time indicated in nbf claim.
Functions ¶
func Decrypt ¶
Decrypt returns the decrypted version of the given data if it's encrypted, it will return the raw data if it's not encrypted or the format is not valid.
func IsAsymmetric ¶
func IsAsymmetric(k *JSONWebKey) bool
Determine whether a JSONWebKey is asymmetric
func ParseKeySet ¶
func ParseKeySet(filename string, opts ...Option) (*jose.JSONWebKey, error)
ParseKeySet returns the JWK with the given key after parsing a JWKSet from a given file. func ParseKeySet(filename, alg, kid string, isSubtle bool) (*jose.JSONWebKey, error) {
func ReadJWKSet ¶
ReadJWKSet reads a JWK Set from a URL or filename. URLs must start with "https://".
func TrimPrefix ¶
TrimPrefix removes the string "square/go-jose" from all errors.
Types ¶
type Builder ¶
Builder is a utility for making JSON Web Tokens. Calls can be chained, and errors are accumulated until the final call to CompactSerialize/FullSerialize.
type ContentEncryption ¶
type ContentEncryption = jose.ContentEncryption
ContentEncryption represents a content encryption algorithm.
type ContentType ¶
type ContentType = jose.ContentType
ContentType represents type of the contained data.
type Encrypter ¶
Encrypter represents an encrypter which produces an encrypted JWE object.
func NewEncrypter ¶
func NewEncrypter(enc ContentEncryption, rcpt Recipient, opts *EncrypterOptions) (Encrypter, error)
NewEncrypter creates an appropriate encrypter based on the key type.
type EncrypterOptions ¶
type EncrypterOptions = jose.EncrypterOptions
EncrypterOptions represents options that can be set on new encrypters.
type Expected ¶
Expected defines values used for protected claims validation. If field has zero value then validation is skipped.
type JSONWebEncryption ¶
type JSONWebEncryption = jose.JSONWebEncryption
JSONWebEncryption represents an encrypted JWE object after parsing.
func ParseEncrypted ¶
func ParseEncrypted(input string) (*JSONWebEncryption, error)
ParseEncrypted parses an encrypted message in compact or full serialization format.
type JSONWebKey ¶
type JSONWebKey = jose.JSONWebKey
JSONWebKey represents a public or private key in JWK format.
func GenerateJWK ¶
func GenerateJWK(kty, crv, alg, use, kid string, size int) (jwk *JSONWebKey, err error)
GenerateJWK generates a JWK given the key type, curve, alg, use, kid and the size of the RSA or oct keys if necessary.
func GenerateJWKFromPEM ¶
func GenerateJWKFromPEM(filename string) (*JSONWebKey, error)
GenerateJWKFromPEM returns an incomplete JSONWebKey using the key from a PEM file.
func ParseKey ¶
func ParseKey(filename string, opts ...Option) (*JSONWebKey, error)
ParseKey returns a JSONWebKey from the given JWK file or a PEM file. For password protected keys, it will ask the user for a password. func ParseKey(filename, use, alg, kid string, subtle bool) (*JSONWebKey, error) {
type JSONWebKeySet ¶
type JSONWebKeySet = jose.JSONWebKeySet
JSONWebKeySet represents a JWK Set object.
type JSONWebSignature ¶
type JSONWebSignature = jose.JSONWebSignature
JSONWebSignature represents a signed JWS object after parsing.
func ParseJWS ¶
func ParseJWS(s string) (*JSONWebSignature, error)
ParseJWS parses a signed message in compact or full serialization format.
type JSONWebToken ¶
type JSONWebToken = jwt.JSONWebToken
JSONWebToken represents a JSON Web Token (as specified in RFC7519).
func ParseSigned ¶
func ParseSigned(s string) (*JSONWebToken, error)
ParseSigned parses token from JWS form.
type KeyAlgorithm ¶
type KeyAlgorithm = jose.KeyAlgorithm
KeyAlgorithm represents a key management algorithm.
type NumericDate ¶
type NumericDate = jwt.NumericDate
NumericDate represents date and time as the number of seconds since the epoch, including leap seconds. Non-integer values can be represented in the serialized format, but we round to the nearest second.
func NewNumericDate ¶
func NewNumericDate(t time.Time) NumericDate
NewNumericDate constructs NumericDate from time.Time value.
type Option ¶
type Option func(ctx *context)
Option is the type used to add attributes to the context.
func WithInsecure ¶
WithInsecure marks the context as insecure.
func WithNoDefaults ¶
WithNoDefaults avoids that the parser loads defaults values, specially the default algorithms.
func WithPassword ¶
WithPassword is a method that adds the given password to the context.
type SignatureAlgorithm ¶
type SignatureAlgorithm = jose.SignatureAlgorithm
SignatureAlgorithm represents a signature (or MAC) algorithm.
type Signer ¶
Signer represents a signer which takes a payload and produces a signed JWS object.
func NewSigner ¶
func NewSigner(sig SigningKey, opts *SignerOptions) (Signer, error)
NewSigner creates an appropriate signer based on the key type
type SignerOptions ¶
type SignerOptions = jose.SignerOptions
SignerOptions represents options that can be set when creating signers.
type SigningKey ¶
type SigningKey = jose.SigningKey
SigningKey represents an algorithm/key used to sign a message.