encryptionkey

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package encryptionkey manages encryption keys for users

Index

Constants

KemID for HPKE protocol.

Variables

This section is empty.

Functions

func DecodeTurnkeyPrivateKey

func DecodeTurnkeyPrivateKey(encodedPrivateKey string) (*kem.PrivateKey, error)

DecodeTurnkeyPrivateKey takes a Turnkey-encoded private key and creates a KEM private key.

func DecodeTurnkeyPublicKey

func DecodeTurnkeyPublicKey(encodedPublicKey string) (*kem.PublicKey, error)

DecodeTurnkeyPublicKey takes a Turnkey-encoded public key and creates a KEM public key.

func EncodePrivateKey

func EncodePrivateKey(privateKey kem.PrivateKey) (string, error)

EncodePrivateKey encodes a KEM private key into the Turnkey format. For now, "Turnkey format" = raw DER form.

func EncodePublicKey

func EncodePublicKey(publicKey kem.PublicKey) (string, error)

EncodePublicKey encodes a KEM public key into the Turnkey format. For now, "Turnkey format" = raw DER form.

Types

type Key

type Key struct {
	Metadata

	TkPrivateKey string `json:"-"` // do not store the private key in the metadata file
	TkPublicKey  string `json:"public_key"`
	// contains filtered or unexported fields
}

Key defines a structure in which to hold both serialized and ecdh-lib-friendly versions of a Turnkey Encryption keypair.

func FromKemPrivateKey

func FromKemPrivateKey(privateKey kem.PrivateKey) (*Key, error)

FromKemPrivateKey takes a HPKE KEM keypair and forms a Turnkey encryption key from it. Assumes that privateKey.Public() has already been derived.

func FromTurnkeyPrivateKey

func FromTurnkeyPrivateKey(encodedPrivateKey string) (*Key, error)

FromTurnkeyPrivateKey takes a Turnkey-encoded private key, derives a public key from it, and then returns the corresponding Turnkey API key.

func New

func New(userID string, organizationID string) (*Key, error)

New generates a new Turnkey encryption key.

func (Key) GetCurve

func (k Key) GetCurve() string

GetCurve returns the curve used.

func (Key) GetMetadata

func (k Key) GetMetadata() Metadata

GetMetadata gets the key's metadata.

func (Key) GetPrivateKey

func (k Key) GetPrivateKey() string

GetPrivateKey gets the key's private key.

func (Key) GetPublicKey

func (k Key) GetPublicKey() string

GetPublicKey gets the key's public key.

func (Key) LoadMetadata

func (k Key) LoadMetadata(fn string) (*Metadata, error)

LoadMetadata loads a JSON metadata file.

func (*Key) MergeMetadata

func (k *Key) MergeMetadata(md Metadata) error

MergeMetadata merges the given metadata with the api key.

type Metadata

type Metadata struct {
	Name         string `json:"name"`
	Organization string `json:"organization"`
	User         string `json:"user"`
	PublicKey    string `json:"public_key"`
}

Metadata stores non-secret metadata about the Encryption key.

Jump to

Keyboard shortcuts

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