crypto

package
v0.0.0-...-7327bce Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSP

type CSP interface {
	// Hash returns the hash data against the specified algorithm
	Hash(algo string, origin []byte) ([]byte, error)

	// Enc returns the encrypted data against the specified algorithm
	Enc(algo, key, keyPwd string, plainText []byte, mode string) ([]byte, error)

	// Dec returns the decrypted data against the specified algorithm
	Dec(algo, key, keyPwd string, cipherText []byte, mode string) ([]byte, error)

	// HMac returns the hmac data against the specified algorithm
	HMac(algo, key string, plain []byte) ([]byte, error)

	// Sign returns the signature data against the specified algorithm
	Sign(algo, key, keyPwd string, plain []byte) ([]byte, error)

	// Verify returns the verification result against the specified algorithm
	Verify(algo, key string, plain, sig []byte) (bool, error)

	// GenSymKey return a fixed length random key against algo
	GenSymKey(algo string, keySize int) ([]byte, error)
}

CSP - crypto service provider

var (
	Csp CSP
)

func InitCrypto

func InitCrypto(cfg *CryptoConfig) (CSP, error)

InitCrypto returns a new crypto instance. support soft and hsm

type CommonConfig

type CommonConfig struct {
	ServerNo string    `yaml:"server_no"`
	Port     int       `yaml:"port"`
	TLS      TLSConfig `yaml:"tls"`
}

CommonConfig - common config

type Config

type Config struct {
	Common CommonConfig `yaml:"common"`
	Log    LogConfig    `yaml:"log"`
	Crypto CryptoConfig `yaml:"crypto"`
	DB     DBConfig     `yaml:"db"`
	Task   TaskConfig   `yaml:"task"`

	SignCrtBytes []byte
	SignKeyBytes []byte
	TlsCrtBytes  []byte
	TlsKeyBytes  []byte
	CaCrtBytes   []byte
}

Config - config

var Conf *Config

Conf -

type CryptoConfig

type CryptoConfig struct {
	Soft    bool   `yaml:"soft"`
	LibPath string `yaml:"lib_path"`
}

CryptoConfig - crypto config

type DBConfig

type DBConfig struct {
	Type string `yaml:"type"`
	URL  string `yaml:"url"`
}

DBConfig - db config

type LogConfig

type LogConfig struct {
	Level    string `yaml:"level"`
	FilePath string `yaml:"file_path"`
}

LogConfig - log config

type TLSConfig

type TLSConfig struct {
	Enable  bool   `yaml:"enable"`
	CrtPath string `yaml:"crt_path"`
	KeyPath string `yaml:"key_path"`
	CaPath  string `yaml:"ca_path"`
	Mutual  bool   `yaml:"mutual"`
}

TLSConfig - tls config for grpc server

type TaskConfig

type TaskConfig struct {
	MaxSpeed int `yaml:"max_speed"`
	Timeout  int `yaml:"timeout"`
}

TaskConfig - task config

Directories

Path Synopsis
base
nolint
nolint
hsmimpl_linux

Jump to

Keyboard shortcuts

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