encryption

package
v1.0.1003 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const SecureField = "__encrypted__"

SecureField - encryption prefix for mongo and mysql

Variables

This section is empty.

Functions

This section is empty.

Types

type EncProvider

type EncProvider interface {
	Init() error
	Keys() (res string)
	CurrentVersion() string
	CurrentVersionInt() int
	CurrentKey() string
	GetKeyVersion(v int) string
	Len() int
	SwitchNextVersion(version int) error
	Version() int
	Provider() string
	Type() string
	KeyId() string
	Encrypt(keyVersion int, data []byte) (cryptData []byte, err error)
	EncryptMany(keyVersion int, data ...[]byte) (cryptData [][]byte, err error)
	Decrypt(keyVersion int, data []byte) (rawData []byte, err error)
	DecryptMany(keyVersion int, data ...[]byte) (rawData [][]byte, err error)
}

EncProvider - interfaces for encryption library or encryption as a services

type Encryption

type Encryption interface {
	MongoEncrypt(data interface{}) (res interface{}, err error)
	MongoDecrypt(data interface{}, dest interface{}) (err error)
	SqlScheme(data interface{}) (val interface{}, name string, err error)
	SqlEncrypt(data interface{}) (val interface{}, err error)
	SqlDecrypt(src, dst interface{}) (err error)
	DefaultProvider() EncProvider
	Provider(providerId, keyId string) EncProvider
	CreateSqlMeta(provider EncProvider) SqlEncMeta
	CreateMeta(provider EncProvider) Meta
	GetKeyId(keyId string) string
	GetKeyVersion(keyId string) (version int)
	Hash(data []byte) []byte
}

type KeyProvider

type KeyProvider int
const (
	ProviderEnv KeyProvider = iota + 1
)

type KeyProviderConfig

type KeyProviderConfig struct {
	// KeyProvider - provider id, cons Provider
	Provider KeyProvider `validate:"required"`
	// Default - use for default new encryption
	Default bool
	// Env - env key secret name
	Env string
}

KeyProviderConfig - provider config

type Meta

type Meta struct {
	Version    int    `json:"version" bson:"version"`
	Provider   string `json:"provider" bson:"provider"`
	Type       string `json:"type" bson:"type"`
	Id         string `json:"id" bson:"id"`
	KeyVersion int    `json:"-" bson:"-" ignored:"true"`
}

Meta - for encryption meta, sql or mongo

type Provider

type Provider interface {
	DefaultProvider() EncProvider
	CreateSqlMeta(provider EncProvider) SqlEncMeta
	CreateMeta(provider EncProvider) Meta
	Provider(providerId, keyId string) EncProvider
	Hash(data []byte) []byte
}

type SqlEncMeta

type SqlEncMeta struct {
	Version    int    `json:"version"`
	Provider   string `json:"provider"`
	Type       string `json:"type"`
	Id         string `json:"id"`
	KeyVersion int    `json:"-"`
}

SqlEncMeta - for sql encryption meta

Jump to

Keyboard shortcuts

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