asymmetric

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateEcdsaSetting

type CreateEcdsaSetting struct {
	Curve elliptic.Curve
}

type CreateRsaSetting

type CreateRsaSetting struct {
	Length int
}

type CryptEncrypt

type CryptEncrypt interface {

	// Encrypt 加密
	Encrypt(keyPair KeyPair, raw []byte) ([]byte, error)

	// EncryptBase64 使用标准Base64传递的数据进行加密
	EncryptBase64(keyPair KeyPair, base64Raw string) (string, error)

	// Decrypt 解密
	Decrypt(keyPair KeyPair, cipher []byte) ([]byte, error)

	// DecryptBase64 使用标准Base64传递的数据进行解密
	DecryptBase64(keyPair KeyPair, base64Cipher string) (string, error)
}

type CryptSign

type CryptSign interface {

	// Sign 数据签名
	Sign(keyPair KeyPair, raw []byte) ([]byte, error)

	// Verify 签名验证
	Verify(keyPair KeyPair, raw, sign []byte) error

	// SignBase64 使用标准Base64传递的数据进行加签
	SignBase64(keyPair KeyPair, base64Raw string) (string, error)

	// VerifyBase64 使用标准Base64传递的数据进行验签
	VerifyBase64(keyPair KeyPair, base64Raw, base64Sign string) error
}

type EcdsaKeyManager

type EcdsaKeyManager struct {
	CreateSetting CreateEcdsaSetting
}

func (*EcdsaKeyManager) Create

func (e *EcdsaKeyManager) Create() (KeyPair, error)

func (*EcdsaKeyManager) Load

func (e *EcdsaKeyManager) Load() (KeyPair, error)

type EcdsaSign

type EcdsaSign struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewEcdsaSign

func NewEcdsaSign(hash hash.Hash) *EcdsaSign

func (*EcdsaSign) Sign

func (e *EcdsaSign) Sign(keyPair KeyPair, raw []byte) ([]byte, error)

func (*EcdsaSign) SignBase64

func (e *EcdsaSign) SignBase64(keyPair KeyPair, base64Raw string) (string, error)

func (*EcdsaSign) SignRS

func (e *EcdsaSign) SignRS(keyPair KeyPair, raw []byte) (*big.Int, *big.Int, error)

func (*EcdsaSign) Verify

func (e *EcdsaSign) Verify(keyPair KeyPair, raw, sign []byte) error

func (*EcdsaSign) VerifyBase64

func (e *EcdsaSign) VerifyBase64(keyPair KeyPair, base64Raw, base64Sign string) error

func (*EcdsaSign) VerifyRS

func (e *EcdsaSign) VerifyRS(keyPair KeyPair, raw []byte, r, s *big.Int) (bool, error)

type KeyPair

type KeyPair interface {
	// PrivateKey 获取原始私钥
	PrivateKey() interface{}
	// PublicKey 获取原始公钥信息
	PublicKey() interface{}
}

KeyPair 公私钥信息

type KeyPairManager

type KeyPairManager interface {
	// Create 生成新的公私钥对
	Create() (KeyPair, error)
	// Load 加载公私钥
	Load() (KeyPair, error)
}

KeyPairManager KeyPair管理器

type PaddingType

type PaddingType uint8
const (
	// PaddingTypeNone 无填充
	PaddingTypeNone PaddingType = 0
	// PaddingTypePKCS1 PKCS1.5
	PaddingTypePKCS1 PaddingType = 1
	// PaddingTypeOAEP OAEP模式
	PaddingTypeOAEP PaddingType = 2
	// PaddingTypePSS PSS模式
	PaddingTypePSS PaddingType = 3
)

type RsaEncrypt

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

func NewRsaEncryptWithOAEP

func NewRsaEncryptWithOAEP(hash hash.Hash, label []byte) (*RsaEncrypt, error)

NewRsaEncryptWithOAEP 创建一个标准的RSA加密 Padding-OAEP模式实例

func NewRsaEncryptWithPKCS1

func NewRsaEncryptWithPKCS1() *RsaEncrypt

NewRsaEncryptWithPKCS1 创建一个标准的RSA加密 Padding-PKCS1模式实例

func (*RsaEncrypt) Decrypt

func (r *RsaEncrypt) Decrypt(keyPair KeyPair, cipher []byte) ([]byte, error)

func (*RsaEncrypt) DecryptBase64

func (r *RsaEncrypt) DecryptBase64(keyPair KeyPair, base64Cipher string) (string, error)

func (*RsaEncrypt) Encrypt

func (r *RsaEncrypt) Encrypt(keyPair KeyPair, raw []byte) ([]byte, error)

func (*RsaEncrypt) EncryptBase64

func (r *RsaEncrypt) EncryptBase64(keyPair KeyPair, base64Raw string) (string, error)

type RsaKeyManager

type RsaKeyManager struct {
	CreateSetting CreateRsaSetting
}

func (*RsaKeyManager) Create

func (r *RsaKeyManager) Create() (KeyPair, error)

func (*RsaKeyManager) Load

func (r *RsaKeyManager) Load() (KeyPair, error)

type RsaSign

type RsaSign struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRsaSignWithPKCS1

func NewRsaSignWithPKCS1(hash hash.Hash, hashType crypto.Hash) (*RsaSign, error)

NewRsaSignWithPKCS1 创建一个标准RSA签名 Padding-PKCS1 自定义hash函数

func NewRsaSignWithPKCS1AndSHA256

func NewRsaSignWithPKCS1AndSHA256() *RsaSign

NewRsaSignWithPKCS1AndSHA256 创建一个标准RSA签名 Padding-PKCS1 hash函数为sha256

func NewRsaSignWithPKCS1AndSHA512

func NewRsaSignWithPKCS1AndSHA512() *RsaSign

NewRsaSignWithPKCS1AndSHA512 创建一个标准RSA签名 Padding-PKCS1 hash函数为sha512

func NewRsaSignWithPSS

func NewRsaSignWithPSS(hash hash.Hash, hashType crypto.Hash) (*RsaSign, error)

NewRsaSignWithPSS 创建一个标准RSA签名 Padding-PSS

func NewRsaSignWithPSSAndOps

func NewRsaSignWithPSSAndOps(hash hash.Hash, hashType crypto.Hash, saltLength int) (*RsaSign, error)

NewRsaSignWithPSSAndOps NewRsaSignWithPSS 创建一个标准RSA签名 Padding-PSS 并指定saltLength

func NewRsaSignWithPSSAndSHA256

func NewRsaSignWithPSSAndSHA256(saltLength ...int) *RsaSign

NewRsaSignWithPSSAndSHA256 创建一个标准RSA签名 Padding-PSS hash函数为sha256

func NewRsaSignWithPSSAndSHA512

func NewRsaSignWithPSSAndSHA512(saltLength ...int) *RsaSign

NewRsaSignWithPSSAndSHA512 创建一个标准RSA签名 Padding-PSS hash函数为sha512

func (*RsaSign) Sign

func (r *RsaSign) Sign(keyPair KeyPair, raw []byte) ([]byte, error)

func (*RsaSign) SignBase64

func (r *RsaSign) SignBase64(keyPair KeyPair, base64Raw string) (string, error)

func (*RsaSign) Verify

func (r *RsaSign) Verify(keyPair KeyPair, raw, sign []byte) error

Verify 签名验证

func (*RsaSign) VerifyBase64

func (r *RsaSign) VerifyBase64(keyPair KeyPair, base64Raw, base64Sign string) error

Jump to

Keyboard shortcuts

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