keys

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 6 Imported by: 3

README

keys

keys 模块提供一组接口,用来管理 starter app 中的密钥

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLibModule

func NewLibModule() *application.ModuleBuilder

NewLibModule ...

func NewMainModule

func NewMainModule() *application.ModuleBuilder

NewMainModule ...

func NewTestModule

func NewTestModule() *application.ModuleBuilder

NewTestModule ...

Types

type CipherMethod

type CipherMethod int

CipherMethod 表示密钥的操作方法

const (
	CipherMethodNone CipherMethod = iota

	CipherMethodDecrypt
	CipherMethodEncrypt
)

定义密钥的操作方法

func (CipherMethod) String

func (m CipherMethod) String() string

type Class

type Class string

Class 表示密钥类型

const (
	ClassPrivateKey Class = "private" // 私钥
	ClassPublicKey  Class = "public"  // 公钥
	ClassSecretKey  Class = "secret"  // 对称密钥
)

定义各种密钥类型

type ComplexAlgorithm

type ComplexAlgorithm string

ComplexAlgorithm 是一组由多个单词构成的字符串,表示一组由多种算法构成的密码学套件 它在形式上,可以是: 驼峰命名,如: "SHA256withRSA"; 下划线分隔的小写字符,如: "sha256_with_rsa"; 下划线分隔的大写字符,如: "SHA256_WITH_RSA"; 空格分隔的小写(或大写)字符,如: "SHA256 WITH RSA"; 等。。。 默认形式为:"sha256_with_rsa"

func NewComplexAlgorithm

func NewComplexAlgorithm(words []string) ComplexAlgorithm

NewComplexAlgorithm 新建算法字符串

func (ComplexAlgorithm) Normalize

func (a ComplexAlgorithm) Normalize() ComplexAlgorithm

Normalize 标准化算法字符串

func (ComplexAlgorithm) String

func (a ComplexAlgorithm) String() string

func (ComplexAlgorithm) ToArray

func (a ComplexAlgorithm) ToArray() []string

ToArray 把这个 ComplexAlgorithm 解析为数组

type Crypt

type Crypt struct {
	Flow    FlowMode    // 数据块串流模式
	Padding PaddingMode // 填充模式
	Random  io.Reader   // 随机数生成器
	IV      []byte      // 初始化向量
	Hash    crypto.Hash // 摘要算法

	CipherText []byte // 密文
	PlainText  []byte // 明文
}

Crypt 承载加密数据

type Decrypter

type Decrypter interface {
	Decrypt(e *Crypt) error
	Block() cipher.Block
}

Decrypter ...

type Driver

type Driver interface {
	Algorithm() string

	Class() Class

	ListRegistrations() []*DriverRegistration
}

Driver 代表密钥的驱动

type DriverManager

type DriverManager interface {
	Find(algorithm string, class Class) (Driver, error)

	FindSecretKeyDriver(algorithm string) (SecretKeyDriver, error)

	FindPublicKeyDriver(algorithm string) (PublicKeyDriver, error)

	FindPrivateKeyDriver(algorithm string) (PrivateKeyDriver, error)
}

DriverManager 代表密钥驱动管理器

type DriverRegistration

type DriverRegistration struct {
	Algorithm string
	Class     Class
	Enabled   bool
	Priority  int
	Driver    Driver
}

DriverRegistration 包含驱动的注册信息

type Encrypter

type Encrypter interface {
	Block() cipher.Block
	Encrypt(e *Crypt) error
}

Encrypter ...

type FlowMode

type FlowMode int

FlowMode 表示密钥的串联模式

const (
	FlowModeNone FlowMode = iota

	// Cipher Block Chaining
	FlowModeCBC

	// Cipher Feed Back
	FlowModeCFB

	// Counter
	FlowModeCTR

	// Galois/Counter Mode
	FlowModeGCM

	// Output Feed Back
	FlowModeOFB
)

定义密钥的串联模式

func (FlowMode) String

func (m FlowMode) String() string

type Key

type Key interface {
	BaseDriver() Driver

	Class() Class

	Export(want *KeyData) (*KeyData, error)

	Fingerprint(h crypto.Hash) []byte
}

Key ...

type KeyData

type KeyData struct {
	Algorithm   string // like 'rsa'
	Encoding    string // like 'x509'
	Format      string // like 'pem'
	ContentType string // like 'application/x-pem'
	Content     []byte
}

KeyData 包含密钥的序列化数据

type Options

type Options struct {
	Size int // in bits

	Flow    FlowMode
	Padding PaddingMode
	Hash    crypto.Hash
	Random  io.Reader
	IV      []byte
}

Options 是通用的选项

type Padding

type Padding interface {
	Mode() PaddingMode

	AddPadding(src []byte, blockSize int) ([]byte, error)

	RemovePadding(src []byte, blockSize int) ([]byte, error)
}

Padding 是填充算法的接口

type PaddingMode

type PaddingMode int

PaddingMode 代表一种填充模式

const (
	PaddingModeNone PaddingMode = iota

	// for secret-key
	NoPadding
	PaddingPKCS7
	PaddingPKCS5
	PaddingZeros
	PaddingISO10126
	PaddingANSIX923

	// for RSA
	PaddingOAEP
	PaddingPKCS1v15
	PaddingSessionKey
	PaddingPSS
)

定义一些常用的填充模式

func (PaddingMode) String

func (p PaddingMode) String() string

type PrivateKey

type PrivateKey interface {
	Key

	PublicKey() PublicKey

	Decrypter() Decrypter

	Signer() Signer

	Native() PrivateKeyNative

	Driver() PrivateKeyDriver
}

PrivateKey ...

type PrivateKeyDriver

type PrivateKeyDriver interface {
	Driver

	Loader() PrivateKeyLoader

	Generator() PrivateKeyGenerator
}

PrivateKeyDriver 代表密钥对的驱动接口

type PrivateKeyGenerator

type PrivateKeyGenerator interface {
	Generate(opt *Options) (PrivateKey, error)
}

PrivateKeyGenerator ... 代表密钥对的 生成器 接口

type PrivateKeyLoader

type PrivateKeyLoader interface {
	Load(kd *KeyData) (PrivateKey, error)
}

PrivateKeyLoader ... 代表密钥对的 加载器 接口

type PrivateKeyNative

type PrivateKeyNative interface {
	Signer() crypto.Signer

	Decrypter() crypto.Decrypter
}

PrivateKeyNative ...

type PublicKey

type PublicKey interface {
	Key

	Driver() PublicKeyDriver

	Encrypter() Encrypter

	Verifier() Verifier
}

PublicKey ...

type PublicKeyDriver

type PublicKeyDriver interface {
	Driver

	Loader() PublicKeyLoader
}

PublicKeyDriver 代表公钥的驱动接口

type PublicKeyLoader

type PublicKeyLoader interface {
	Load(kd *KeyData) (PublicKey, error)
}

PublicKeyLoader ... 代表公钥的 加载器 接口

type SecretKey

type SecretKey interface {
	Key

	Driver() SecretKeyDriver

	Decrypter() Decrypter

	Encrypter() Encrypter

	Native() SecretKeyNative
}

SecretKey ...

type SecretKeyDriver

type SecretKeyDriver interface {
	Driver

	Loader() SecretKeyLoader

	Generator() SecretKeyGenerator
}

SecretKeyDriver 代表对称密钥的驱动接口

type SecretKeyGenerator

type SecretKeyGenerator interface {
	Generate(opt *Options) (SecretKey, error)
}

SecretKeyGenerator ... 代表密钥的 生成器 接口

type SecretKeyLoader

type SecretKeyLoader interface {
	Load(kd *KeyData) (SecretKey, error)
}

SecretKeyLoader ... 代表密钥的 加载器 接口

type SecretKeyNative

type SecretKeyNative interface {
	Key() SecretKey

	NewCipher() (cipher.Block, error)
}

SecretKeyNative ...

type Signature

type Signature struct {
	Random     io.Reader
	SaltLength int
	Hash       crypto.Hash
	Padding    PaddingMode

	Digest    []byte
	Signature []byte
}

Signature ...

type Signer

type Signer interface {
	Sign(s *Signature) error
}

Signer ...

type Verifier

type Verifier interface {
	Verify(s *Signature) error
}

Verifier 代表签名验证器

Jump to

Keyboard shortcuts

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