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 Decrypter
- func (d *Decrypter) AgreementPartyUInfo(apu []byte) *Decrypter
- func (d *Decrypter) AgreementPartyVInfo(apv []byte) *Decrypter
- func (d *Decrypter) AuthenticatedData(aad []byte) *Decrypter
- func (d *Decrypter) BuildKeyDecrypter() (keyenc.Decrypter, error)
- func (d *Decrypter) ComputedAuthenticatedData(aad []byte) *Decrypter
- func (d *Decrypter) ContentCipher() (content_crypt.Cipher, error)
- func (d *Decrypter) ContentEncryptionAlgorithm(ctalg jwa.ContentEncryptionAlgorithm) *Decrypter
- func (d *Decrypter) Decrypt(recipientKey, ciphertext []byte) (plaintext []byte, err error)
- func (d *Decrypter) DecryptKey(recipientKey []byte) (cek []byte, err error)
- func (d *Decrypter) InitializationVector(iv []byte) *Decrypter
- func (d *Decrypter) KeyCount(keycount int) *Decrypter
- func (d *Decrypter) KeyInitializationVector(keyiv []byte) *Decrypter
- func (d *Decrypter) KeySalt(keysalt []byte) *Decrypter
- func (d *Decrypter) KeyTag(keytag []byte) *Decrypter
- func (d *Decrypter) PublicKey(pubkey interface{}) *Decrypter
- func (d *Decrypter) Tag(tag []byte) *Decrypter
- 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" CountKey = "p2c" InitializationVectorKey = "iv" ProtectedHeadersKey = "protected" RecipientsKey = "recipients" SaltKey = "p2s" TagKey = "tag" UnprotectedHeadersKey = "unprotected" HeadersKey = "header" EncryptedKeyKey = "encrypted_key" )
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 Decrypter ¶ added in v1.0.6
type Decrypter struct {
// contains filtered or unexported fields
}
Decrypter is responsible for taking various components to decrypt a message. its operation is not concurrency safe. You must provide locking yourself
func NewDecrypter ¶ added in v1.0.6
func NewDecrypter(keyalg jwa.KeyEncryptionAlgorithm, ctalg jwa.ContentEncryptionAlgorithm, privkey interface{}) *Decrypter
NewDecrypter Creates a new Decrypter instance. You must supply the rest of parameters via their respective setter methods before calling Decrypt().
privkey must be a private key in its "raw" format (i.e. something like *rsa.PrivateKey, instead of jwk.Key)
You should consider this object immutable once you assign values to it.
func (*Decrypter) AgreementPartyUInfo ¶ added in v1.0.6
func (*Decrypter) AgreementPartyVInfo ¶ added in v1.0.6
func (*Decrypter) AuthenticatedData ¶ added in v1.0.6
func (*Decrypter) BuildKeyDecrypter ¶ added in v1.0.6
func (*Decrypter) ComputedAuthenticatedData ¶ added in v1.0.6
func (*Decrypter) ContentCipher ¶ added in v1.0.6
func (d *Decrypter) ContentCipher() (content_crypt.Cipher, error)
func (*Decrypter) ContentEncryptionAlgorithm ¶ added in v1.0.6
func (d *Decrypter) ContentEncryptionAlgorithm(ctalg jwa.ContentEncryptionAlgorithm) *Decrypter
func (*Decrypter) DecryptKey ¶ added in v1.0.6
func (*Decrypter) InitializationVector ¶ added in v1.0.6
func (*Decrypter) KeyInitializationVector ¶ added in v1.0.6
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 returns the map containing the non-standard ('private') parameters // in the associated header. WARNING: DO NOT USE PrivateParams() // IF YOU HAVE CONCURRENT CODE ACCESSING THEM. Use AsMap() to // get a copy of the entire header instead PrivateParams() map[string]interface{} Clone(context.Context) (Headers, error) Copy(context.Context, Headers) error Merge(context.Context, Headers) (Headers, error) }
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