hpke

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package hpke contains functions for working with Hybrid Public Key Encryption.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncryptURLValuesV1 added in v0.23.0

func EncryptURLValuesV1(
	senderPrivateKey *PrivateKey,
	receiverPublicKey *PublicKey,
	values url.Values,
) (encrypted url.Values, err error)

EncryptURLValuesV1 encrypts URL values using the Seal method.

func EncryptURLValuesV2 added in v0.23.0

func EncryptURLValuesV2(
	senderPrivateKey *PrivateKey,
	receiverPublicKey *PublicKey,
	values url.Values,
) (encrypted url.Values, err error)

EncryptURLValuesV2 encrypts URL values using the Seal method and compresses the query string.

func IsEncryptedURL

func IsEncryptedURL(values url.Values) bool

IsEncryptedURL returns true if the url.Values contain an HPKE encrypted query.

func IsEncryptedURLV1 added in v0.23.0

func IsEncryptedURLV1(values url.Values) bool

IsEncryptedURLV1 returns true if the url.Values contain a V1 HPKE encrypted query.

func IsEncryptedURLV2 added in v0.23.0

func IsEncryptedURLV2(values url.Values) bool

IsEncryptedURLV2 returns true if the url.Values contains a V2 HPKE encrypted query.

func Open

func Open(
	receiverPrivateKey *PrivateKey,
	senderPublicKey *PublicKey,
	sealed []byte,
) (message []byte, err error)

Open opens a message using HPKE.

func Seal

func Seal(
	senderPrivateKey *PrivateKey,
	receiverPublicKey *PublicKey,
	message []byte,
) (sealed []byte, err error)

Seal seales a message using HPKE.

Types

type EncryptURLValuesFunc added in v0.23.0

type EncryptURLValuesFunc func(senderPrivateKey *PrivateKey, receiverPublicKey *PublicKey, values url.Values) (encrypted url.Values, err error)

An EncryptURLValuesFunc is a function that encrypts url values.

type JWK

type JWK struct {
	Type  string `json:"kty"`
	ID    string `json:"kid"`
	Curve string `json:"crv"`
	X     string `json:"x"`
	D     string `json:"d,omitempty"`
}

JWK is the JSON Web Key representation of an HPKE key. Defined in RFC8037.

type KeyFetcher

type KeyFetcher interface {
	FetchPublicKey(ctx context.Context) (*PublicKey, error)
}

A KeyFetcher fetches public keys.

func NewKeyFetcher

func NewKeyFetcher(endpoint string, transport http.RoundTripper) KeyFetcher

NewKeyFetcher returns a new KeyFetcher which fetches keys using an in-memory HTTP cache.

type PrivateKey

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

PrivateKey is an HPKE private key.

func DerivePrivateKey

func DerivePrivateKey(seed []byte) *PrivateKey

DerivePrivateKey derives a private key from a seed. The same seed will always result in the same private key.

func GeneratePrivateKey

func GeneratePrivateKey() (*PrivateKey, error)

GeneratePrivateKey generates an HPKE private key.

func PrivateKeyFromString

func PrivateKeyFromString(raw string) (*PrivateKey, error)

PrivateKeyFromString takes a string and returns a PrivateKey.

func (*PrivateKey) MarshalJSON

func (key *PrivateKey) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON Web Key representation of the private key.

func (*PrivateKey) PublicKey

func (key *PrivateKey) PublicKey() *PublicKey

PublicKey returns the public key for the private key.

func (*PrivateKey) String

func (key *PrivateKey) String() string

String converts the private key into a string.

type PublicKey

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

PublicKey is an HPKE public key.

func DecryptURLValues

func DecryptURLValues(
	receiverPrivateKey *PrivateKey,
	encrypted url.Values,
) (senderPublicKey *PublicKey, values url.Values, err error)

DecryptURLValues decrypts URL values using the Open method.

func FetchPublicKey added in v0.21.3

func FetchPublicKey(ctx context.Context, client *http.Client, endpoint string) (*PublicKey, error)

FetchPublicKey fetches the HPKE public key from the hpke-public-key endpoint.

func PublicKeyFromBytes added in v0.21.3

func PublicKeyFromBytes(raw []byte) (*PublicKey, error)

PublicKeyFromBytes converts raw bytes into a public key.

func PublicKeyFromString

func PublicKeyFromString(raw string) (*PublicKey, error)

PublicKeyFromString converts a string into a public key.

func (*PublicKey) Bytes added in v0.21.3

func (key *PublicKey) Bytes() []byte

Bytes returns the public key as raw bytes.

func (*PublicKey) Equals

func (key *PublicKey) Equals(other *PublicKey) bool

Equals returns true if the two keys are equivalent.

func (*PublicKey) MarshalJSON

func (key *PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON Web Key representation of the public key.

func (*PublicKey) String

func (key *PublicKey) String() string

String converts a public key into a string.

Directories

Path Synopsis
Package handlers provides http handlers for HPKE.
Package handlers provides http handlers for HPKE.

Jump to

Keyboard shortcuts

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