security

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageTypeLocal = "local"
	StorageTypeMysql = "mysql"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

func GetProvider

func GetProvider(ctx context.Context, name string, typ ...string) (p *Provider, err error)

GetProvider of security module, if not exists create with specified type (using storage type "mysql" as default).

try get keypair from Storage it will auto create if not exist both. *notice* make sure every node has the same keypair or maybe cannot decode the encrypted data properly cause of keypair mismatch.

func NewProvider

func NewProvider(ctx context.Context, name, storageType string) (p *Provider, err error)

func (*Provider) Decrypt

func (p *Provider) Decrypt(data interface{}) (s string, err error)

Decrypt using rsa

func (*Provider) Encrypt

func (p *Provider) Encrypt(data interface{}) (s string, err error)

Encrypt using rsa

func (*Provider) GetPublicKeyPem

func (p *Provider) GetPublicKeyPem() string

GetPublicKeyPem get public key pem

type Storage

type Storage interface {
	StorePublicKey(ctx context.Context, name string, data []byte) error
	StorePrivateKey(ctx context.Context, name string, data []byte) error
	LoadPublicKey(ctx context.Context, name string) (publicKey *rsa.PublicKey, err error)
	LoadPrivateKey(ctx context.Context, name string) (privateKey *rsa.PrivateKey, err error)
}

func NewLocalStorage

func NewLocalStorage() Storage

func NewMysqlStorage

func NewMysqlStorage(ctx context.Context) Storage

Jump to

Keyboard shortcuts

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