rsa

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const Name = "rsa"

Variables

View Source
var DefaultDecryptor = NewDecryptor()
View Source
var DefaultEncryptor = NewEncryptor()
View Source
var DefaultSigner = NewSigner()
View Source
var DefaultVerifier = NewVerifier()

Functions

func Decrypt added in v0.0.10

func Decrypt(ciphertext []byte) ([]byte, error)

Decrypt 解密

func Encrypt added in v0.0.10

func Encrypt(data []byte) ([]byte, error)

Encrypt 加密

func Sign added in v0.0.10

func Sign(data []byte) ([]byte, error)

Sign 签名

func Verify added in v0.0.10

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

Verify 验签

Types

type Decryptor

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

func NewDecryptor

func NewDecryptor(opts ...DecryptorOption) *Decryptor

func (*Decryptor) Decrypt

func (d *Decryptor) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt 解密

func (*Decryptor) Name

func (d *Decryptor) Name() string

Name 名称

type DecryptorOption

type DecryptorOption func(o *decryptorOptions)

func WithDecryptorHash

func WithDecryptorHash(hash hash.Hash) DecryptorOption

WithDecryptorHash 设置解密hash算法

func WithDecryptorLabel

func WithDecryptorLabel(label string) DecryptorOption

WithDecryptorLabel 设置解密标签

func WithDecryptorPadding

func WithDecryptorPadding(padding EncryptPadding) DecryptorOption

WithDecryptorPadding 设置解密填充规则

func WithDecryptorPrivateKey

func WithDecryptorPrivateKey(privateKey string) DecryptorOption

WithDecryptorPrivateKey 设置解密私钥

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) 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 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 签名

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 设置解密私钥

type Verifier

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

func NewVerifier

func NewVerifier(opts ...VerifierOption) *Verifier

func (*Verifier) Name

func (v *Verifier) Name() string

Name 名称

func (*Verifier) Verify

func (v *Verifier) Verify(data []byte, signature []byte) (bool, error)

Verify 验签

type VerifierOption

type VerifierOption func(o *verifierOption)

func WithVerifierHash

func WithVerifierHash(hash hash.Hash) VerifierOption

WithVerifierHash 设置加密hash算法

func WithVerifierPadding

func WithVerifierPadding(padding SignPadding) VerifierOption

WithVerifierPadding 设置加密填充规则

func WithVerifierPublicKey

func WithVerifierPublicKey(publicKey string) VerifierOption

WithVerifierPublicKey 设置验签公钥

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

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