Documentation ¶
Overview ¶
This file is auto-generated by internal/cmd/genheaders/main.go. DO NOT EDIT
Package jwe implements JWE as described in https://tools.ietf.org/html/rfc7516
Index ¶
- Constants
- func Compact(m *Message, _ ...Option) ([]byte, error)
- func Decrypt(buf []byte, alg jwa.KeyEncryptionAlgorithm, key interface{}) ([]byte, error)
- func Encrypt(payload []byte, keyalg jwa.KeyEncryptionAlgorithm, key interface{}, ...) ([]byte, error)
- func JSON(m *Message, options ...Option) ([]byte, error)
- type HeaderPair
- type Headers
- type Iterator
- type Message
- func (m *Message) AuthenticatedData() []byte
- func (m *Message) CipherText() []byte
- func (m *Message) Decrypt(alg jwa.KeyEncryptionAlgorithm, key interface{}) ([]byte, error)
- func (m *Message) InitializationVector() []byte
- func (m *Message) MarshalJSON() ([]byte, error)
- func (m *Message) ProtectedHeaders() Headers
- func (m *Message) Recipients() []Recipient
- func (m *Message) Set(k string, v interface{}) error
- func (m *Message) Tag() []byte
- func (m *Message) UnmarshalJSON(buf []byte) error
- func (m *Message) UnprotectedHeaders() Headers
- type Option
- type Recipient
- type Visitor
- type VisitorFunc
Examples ¶
Constants ¶
const ( AgreementPartyUInfoKey = "apu" AgreementPartyVInfoKey = "apv" AlgorithmKey = "alg" CompressionKey = "zip" ContentEncryptionKey = "enc" ContentTypeKey = "cty" CriticalKey = "crit" EphemeralPublicKeyKey = "epk" JWKKey = "jwk" JWKSetURLKey = "jku" KeyIDKey = "kid" TypeKey = "typ" X509CertChainKey = "x5c" X509CertThumbprintKey = "x5t" X509CertThumbprintS256Key = "x5t#S256" X509URLKey = "x5u" )
const ( AuthenticatedDataKey = "aad" CipherTextKey = "ciphertext" InitializationVectorKey = "iv" ProtectedHeadersKey = "protected" RecipientsKey = "recipients" TagKey = "tag" UnprotectedHeadersKey = "unprotected" )
Variables ¶
This section is empty.
Functions ¶
func Compact ¶ added in v1.0.0
Compact encodes the given message into a JWE compact serialization format.
func Decrypt ¶
func Decrypt(buf []byte, alg jwa.KeyEncryptionAlgorithm, key interface{}) ([]byte, error)
Decrypt takes the key encryption algorithm and the corresponding key to decrypt the JWE message, and returns the decrypted payload. The JWE message can be either compact or full JSON format.
func Encrypt ¶
func Encrypt(payload []byte, keyalg jwa.KeyEncryptionAlgorithm, key interface{}, contentalg jwa.ContentEncryptionAlgorithm, compressalg jwa.CompressionAlgorithm) ([]byte, error)
Encrypt takes the plaintext payload and encrypts it in JWE compact format.
Example ¶
privkey, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { log.Printf("failed to generate private key: %s", err) return } payload := []byte("Lorem Ipsum") encrypted, err := Encrypt(payload, jwa.RSA1_5, &privkey.PublicKey, jwa.A128CBC_HS256, jwa.NoCompress) if err != nil { log.Printf("failed to encrypt payload: %s", err) return } decrypted, err := Decrypt(encrypted, jwa.RSA1_5, privkey) if err != nil { log.Printf("failed to decrypt: %s", err) return } if string(decrypted) != "Lorem Ipsum" { log.Printf("WHAT?!") return }
Output:
Types ¶
type HeaderPair ¶ added in v1.0.0
type Headers ¶ added in v1.0.0
type Headers interface { AgreementPartyUInfo() buffer.Buffer AgreementPartyVInfo() buffer.Buffer Algorithm() jwa.KeyEncryptionAlgorithm Compression() jwa.CompressionAlgorithm ContentEncryption() jwa.ContentEncryptionAlgorithm ContentType() string Critical() []string EphemeralPublicKey() jwk.ECDSAPublicKey JWK() jwk.Key JWKSetURL() string KeyID() string Type() string X509CertChain() []string X509CertThumbprint() string X509CertThumbprintS256() string X509URL() string Iterate(ctx context.Context) Iterator Walk(ctx context.Context, v Visitor) error AsMap(ctx context.Context) (map[string]interface{}, error) Get(string) (interface{}, bool) Set(string, interface{}) error Remove(string) error Encode() ([]byte, error) Decode([]byte) error PrivateParams() map[string]interface{} }
Headers describe a standard Header set.
func NewHeaders ¶ added in v1.0.0
func NewHeaders() Headers
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message contains the entire encrypted JWE message
func Parse ¶
Parse parses the JWE message into a Message object. The JWE message can be either compact or full JSON format.
func ParseString ¶
ParseString is the same as Parse, but takes a string.
func (*Message) AuthenticatedData ¶
func (*Message) CipherText ¶
func (*Message) Decrypt ¶
func (m *Message) Decrypt(alg jwa.KeyEncryptionAlgorithm, key interface{}) ([]byte, error)
Decrypt decrypts the message using the specified algorithm and key
func (*Message) InitializationVector ¶
func (*Message) MarshalJSON ¶ added in v1.0.0
func (*Message) ProtectedHeaders ¶ added in v1.0.0
func (*Message) Recipients ¶
func (*Message) UnmarshalJSON ¶ added in v1.0.0
func (*Message) UnprotectedHeaders ¶ added in v1.0.0
type Option ¶ added in v1.0.0
func WithPrettyJSONFormat ¶ added in v1.0.0
WithPrettyJSONFormat specifies if the `jwe.JSON` serialization tool should generate pretty-formatted output
type Recipient ¶
type Recipient interface { Headers() Headers EncryptedKey() buffer.Buffer SetHeaders(Headers) error SetEncryptedKey(interface{}) error }
Recipient holds the encrypted key and hints to decrypt the key
type Visitor ¶ added in v1.0.0
type Visitor = iter.MapVisitor
type VisitorFunc ¶ added in v1.0.0
type VisitorFunc = iter.MapVisitorFunc