encryption

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key")
	ErrNotRSAPrivateKey    = errors.New("Key is not a valid RSA private key")
	ErrNotRSAPublicKey     = errors.New("Key is not a valid RSA public key")
)

Functions

This section is empty.

Types

type RSAEncryptor

type RSAEncryptor struct {
	CertificateSerialNo string          // 签名证书序列号
	PublicKeyPath       string          // 签名公钥路径
	PublicKey           *rsa.PublicKey  // 签名公钥
	PrivateKeyPath      string          // 签名私钥路径,会自动读取出*rsa.PrivateKey
	PrivateKey          *rsa.PrivateKey // 签名私钥
	Hash                crypto.Hash
}

func NewRSAEncryptor

func NewRSAEncryptor(hash crypto.Hash) (encryptor *RSAEncryptor, err error)

func (*RSAEncryptor) Alg

func (encryptor *RSAEncryptor) Alg() string

func (*RSAEncryptor) Decryption

func (encryptor *RSAEncryptor) Decryption(ciphertext []byte) (plainText []byte, err error)

Decryption optHash recommend use crypto.SHA256 as hash

func (*RSAEncryptor) Encrypt

func (encryptor *RSAEncryptor) Encrypt(data []byte) ([]byte, error)

Encrypt hash recommend use sha256.New() as hash

func (*RSAEncryptor) GenerateKey

func (encryptor *RSAEncryptor) GenerateKey(bit int) (privateKey *rsa.PrivateKey, err error)

func (*RSAEncryptor) LoadPrivateKeyByPath

func (encryptor *RSAEncryptor) LoadPrivateKeyByPath() (privateKey *rsa.PrivateKey, err error)

func (*RSAEncryptor) LoadPublicKeyByPath

func (encryptor *RSAEncryptor) LoadPublicKeyByPath() (publicKey *rsa.PublicKey, err error)

func (*RSAEncryptor) ParseRSAPrivateKeyFromPEM

func (encryptor *RSAEncryptor) ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)

func (*RSAEncryptor) ParseRSAPrivateKeyFromPEMWithPassword

func (encryptor *RSAEncryptor) ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)

Parse PEM encoded PKCS1 or PKCS8 private key protected with password

func (*RSAEncryptor) ParseRSAPublicKeyFromPEM

func (encryptor *RSAEncryptor) ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)

func (*RSAEncryptor) SavePrivateKeyByPath

func (encryptor *RSAEncryptor) SavePrivateKeyByPath(path string) (err error)

func (*RSAEncryptor) SavePublicKeyByPath

func (encryptor *RSAEncryptor) SavePublicKeyByPath(path string) (err error)

Jump to

Keyboard shortcuts

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