crypto

package
v1.0.0-rc7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64String

func Base64String(size int) (string, error)

func EncryptedDataKeyID

func EncryptedDataKeyID(value []byte) (uuid.UUID, bool, error)

func HashPassword added in v0.0.18

func HashPassword(password string) (string, error)

HashPassword hashes a plaintext password using bcrypt

func HashToken

func HashToken(token string) string

func NewRandomKey

func NewRandomKey(ctx context.Context, encryptor Encryptor, name string) (string, []byte, error)

func SHA256ForMap

func SHA256ForMap(m map[string]string) (string, error)

func SetProcessEncryptor

func SetProcessEncryptor(encryptor Encryptor)

SetProcessEncryptor makes the server's initialized encryptor available to code paths that run outside dependency-injected request and worker contexts.

func Sign added in v0.12.0

func Sign(key []byte, data []byte) string

func VerifyPassword added in v0.0.18

func VerifyPassword(hash, password string) bool

VerifyPassword verifies a plaintext password against a bcrypt hash

func VerifySignature

func VerifySignature(key []byte, data []byte, signature string) error

Types

type ConfiguredMasterKeys

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

func (*ConfiguredMasterKeys) Has

func (k *ConfiguredMasterKeys) Has(reference string) bool

func (*ConfiguredMasterKeys) Unwrap

func (k *ConfiguredMasterKeys) Unwrap(ctx context.Context, reference string, wrapped, associatedData []byte) ([]byte, error)

func (*ConfiguredMasterKeys) Wrap

func (k *ConfiguredMasterKeys) Wrap(ctx context.Context, reference string, plain, associatedData []byte) ([]byte, error)

type DataKey

type DataKey struct {
	ID       uuid.UUID
	Material []byte
}

type DataKeys

type DataKeys interface {
	Active(context.Context) (DataKey, error)
	Find(context.Context, uuid.UUID) (DataKey, error)
}

type Encryptor

type Encryptor interface {
	Encrypt(context.Context, []byte, []byte) ([]byte, error)
	Decrypt(context.Context, []byte, []byte) ([]byte, error)
}

func NewNoOpEncryptor

func NewNoOpEncryptor() Encryptor

func ProcessEncryptor

func ProcessEncryptor() (Encryptor, error)

type GCPMasterKeys

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

GCPMasterKeys wraps data keys with the configured Cloud KMS CryptoKeys.

func NewGCPMasterKeys

func NewGCPMasterKeys(ctx context.Context, configured string) (*GCPMasterKeys, error)

func (*GCPMasterKeys) Has

func (k *GCPMasterKeys) Has(reference string) bool

func (*GCPMasterKeys) Unwrap

func (k *GCPMasterKeys) Unwrap(ctx context.Context, reference string, wrapped, associatedData []byte) ([]byte, error)

func (*GCPMasterKeys) Wrap

func (k *GCPMasterKeys) Wrap(ctx context.Context, reference string, plain, associatedData []byte) ([]byte, error)

type LocalMasterKeys

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

func ParseLocalMasterKeys

func ParseLocalMasterKeys(configured string) (*LocalMasterKeys, error)

func (*LocalMasterKeys) Has

func (k *LocalMasterKeys) Has(reference string) bool

func (*LocalMasterKeys) Unwrap

func (k *LocalMasterKeys) Unwrap(_ context.Context, reference string, wrapped, associatedData []byte) ([]byte, error)

func (*LocalMasterKeys) Wrap

func (k *LocalMasterKeys) Wrap(_ context.Context, reference string, plain, associatedData []byte) ([]byte, error)

type MasterKeys

type MasterKeys interface {
	Wrap(context.Context, string, []byte, []byte) ([]byte, error)
	Unwrap(context.Context, string, []byte, []byte) ([]byte, error)
	Has(string) bool
}

MasterKeys protects data encryption keys. A reference identifies the configured master key; it never contains secret key material.

func MasterKeysFromEnv

func MasterKeysFromEnv(ctx context.Context) (MasterKeys, string, error)

type NoOpEncryptor

type NoOpEncryptor struct {
}

func (*NoOpEncryptor) Decrypt

func (e *NoOpEncryptor) Decrypt(ctx context.Context, data []byte, associatedData []byte) ([]byte, error)

func (*NoOpEncryptor) Encrypt

func (e *NoOpEncryptor) Encrypt(ctx context.Context, data []byte, associatedData []byte) ([]byte, error)

type VersionedEncryptor

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

func NewVersionedEncryptor

func NewVersionedEncryptor(keys DataKeys) *VersionedEncryptor

func (*VersionedEncryptor) Decrypt

func (e *VersionedEncryptor) Decrypt(ctx context.Context, value, associatedData []byte) ([]byte, error)

func (*VersionedEncryptor) Encrypt

func (e *VersionedEncryptor) Encrypt(ctx context.Context, plain, associatedData []byte) ([]byte, error)

func (*VersionedEncryptor) WithKeys

func (e *VersionedEncryptor) WithKeys(keys DataKeys) *VersionedEncryptor

Jump to

Keyboard shortcuts

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