rsa

package module
v2.0.0-...-5372cc7 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "rsa"

Variables

This section is empty.

Functions

This section is empty.

Types

type EncryptPadding

type EncryptPadding string

EncryptPadding 加密填充算法

const (
	NORMAL EncryptPadding = "NORMAL" // RSA_PKCS1_PADDING,数据切割加密长度算法为
	OAEP   EncryptPadding = "OAEP"   // RSA_PKCS1_OAEP_PADDING,数据切割加密长度算法为:公共模数长度-(2*哈希长度的)-2
)

type Encryptor

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

func NewEncryptor

func NewEncryptor(opts ...EncryptorOption) *Encryptor

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt 解密

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(data []byte) ([]byte, error)

Encrypt 加密

func (*Encryptor) Name

func (e *Encryptor) Name() string

Name 名称

type EncryptorOption

type EncryptorOption func(o *encryptorOptions)

func WithEncryptorBlockSize

func WithEncryptorBlockSize(blockSize int) EncryptorOption

WithEncryptorBlockSize 设置加密数据块大小

func WithEncryptorHash

func WithEncryptorHash(hash hash.Hash) EncryptorOption

WithEncryptorHash 设置加密hash算法

func WithEncryptorLabel

func WithEncryptorLabel(label string) EncryptorOption

WithEncryptorLabel 设置加密标签

func WithEncryptorPadding

func WithEncryptorPadding(padding EncryptPadding) EncryptorOption

WithEncryptorPadding 设置加密填充规则

func WithEncryptorPrivateKey

func WithEncryptorPrivateKey(privateKey string) EncryptorOption

WithEncryptorPrivateKey 设置解密私钥

func WithEncryptorPublicKey

func WithEncryptorPublicKey(publicKey string) EncryptorOption

WithEncryptorPublicKey 设置加密公钥

type Format

type Format int
const (
	PKCS1 Format = iota
	PKCS8
)

type Key

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

func GenerateKey

func GenerateKey(bits int) (*Key, error)

GenerateKey 生成秘钥

func (*Key) MarshalPrivateKey

func (k *Key) MarshalPrivateKey(format Format) ([]byte, error)

MarshalPrivateKey 编码私钥

func (*Key) MarshalPublicKey

func (k *Key) MarshalPublicKey(format Format) ([]byte, error)

MarshalPublicKey 编码公钥

func (*Key) PrivateKey

func (k *Key) PrivateKey() *rsa.PrivateKey

PrivateKey 获取私钥

func (*Key) PublicKey

func (k *Key) PublicKey() *rsa.PublicKey

PublicKey 获取公钥

func (*Key) SaveKeyPair

func (k *Key) SaveKeyPair(format Format, dir string, file string) (err error)

SaveKeyPair 保存秘钥对

type SignPadding

type SignPadding string

SignPadding 签名填充算法

const (
	PKCS SignPadding = "PKCS" // RSA PKCS #1 v1.5
	PSS  SignPadding = "PSS"  // RSA PSS
)

type Signer

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

func NewSigner

func NewSigner(opts ...SignerOption) *Signer

func (*Signer) Name

func (s *Signer) Name() string

Name 名称

func (*Signer) Sign

func (s *Signer) Sign(data []byte) ([]byte, error)

Sign 签名

func (*Signer) Verify

func (s *Signer) Verify(data []byte, signature []byte) (bool, error)

Verify 验签

type SignerOption

type SignerOption func(o *signerOptions)

func WithSignerHash

func WithSignerHash(hash hash.Hash) SignerOption

WithSignerHash 设置加密hash算法

func WithSignerPadding

func WithSignerPadding(padding SignPadding) SignerOption

WithSignerPadding 设置加密填充规则

func WithSignerPrivateKey

func WithSignerPrivateKey(privateKey string) SignerOption

WithSignerPrivateKey 设置解密私钥

func WithSignerPublicKey

func WithSignerPublicKey(publicKey string) SignerOption

WithSignerPublicKey 设置验签公钥

Jump to

Keyboard shortcuts

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