jwk

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UseSig = "sig"
	UseEnc = "enc"
)

Standard key use parameters.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("json web key is not found")
)

Functions

This section is empty.

Types

type Key

type Key jose.JSONWebKey

Key is an alias to jose.JSONWebKey to add more functions.

func GenerateEncryptionKey

func GenerateEncryptionKey(kid string, alg string, bits int) *Key

GenerateEncryptionKey generates an encryption Key with the given kid and algorithm.

func GenerateSignatureKey

func GenerateSignatureKey(kid string, alg string, bits int) *Key

GenerateSignatureKey generates a signature Key with the given kid and algorithm.

func (*Key) IsPublicAsymmetric

func (k *Key) IsPublicAsymmetric() bool

IsPublicAsymmetric returns true if the underlying asymmetric key only has the public portion. If called is not sure about the key's symmetry, check with IsSymmetric first.

func (*Key) IsSymmetric

func (k *Key) IsSymmetric() bool

IsSymmetric returns true if the underlying key uses symmetric algorithms (i.e. HS256)

func (*Key) Public

func (k *Key) Public() *Key

Public returns a new Key with only the public portion of the underlying key. This method shall return the same Key if the key is already public or is symmetric.

type KeySet

type KeySet struct {
	// contains filtered or unexported fields
}

func NewKeySet

func NewKeySet(keys ...*Key) *KeySet

NewKeySet creates a new key set with the given keys.

func ReadKeySet

func ReadKeySet(reader io.Reader) (*KeySet, error)

ReadKeySet create new KeySet with data from the reader

func (*KeySet) Count

func (s *KeySet) Count() int

Count returns the number of keys in the set.

func (*KeySet) KeyById

func (s *KeySet) KeyById(kid string) (*Key, error)

KeyById finds a Key by its id value.

func (*KeySet) KeyForEncryption

func (s *KeySet) KeyForEncryption(alg string) (*Key, error)

KeyForEncryption find a key for encryption with the given algorithm. The returned key may be a private key, in which case, caller needs to convert to a public key before use. If multiple encryption keys with the same algorithm exists in the set, the last one based on the current time.

func (*KeySet) KeyForSigning

func (s *KeySet) KeyForSigning(alg string) (*Key, error)

KeyForSigning find a key for signing with the given algorithm. If multiple signing keys with the same algorithm exists in the set, the last one is picked.

func (*KeySet) MarshalJSON

func (s *KeySet) MarshalJSON() ([]byte, error)

func (*KeySet) ToPublic

func (s *KeySet) ToPublic() *KeySet

ToPublic returns a new KeySet with only public asymmetric keys so that it is read to be shared.

func (*KeySet) UnmarshalJSON

func (s *KeySet) UnmarshalJSON(bytes []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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