gorsa

package
v0.0.0-...-5d25ce1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MulanPSL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataToLarge     = errors.New("message too long for RSA public key size")
	ErrDataLen         = errors.New("data length error")
	ErrDataBroken      = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch = errors.New("data is not encrypted by the private key")
	ErrDecryption      = errors.New("decryption error")
	ErrPublicKey       = errors.New("get public key error")
	ErrPrivateKey      = errors.New("get private key error")
)
View Source
var RSA = &RSASecurity{}

Functions

func GetPriKey

func GetPriKey(priPEM []byte) (*rsa.PrivateKey, error)

设置私钥

func GetPubKey

func GetPubKey(pubPEM []byte) (*rsa.PublicKey, error)

设置公钥

func PriKeyDecrypt

func PriKeyDecrypt(data []byte, priPEM string) ([]byte, error)

私钥解密

func PriKeyDecrypt_NoPad

func PriKeyDecrypt_NoPad(msg []byte, priPEM string) string

仅适合0-255的字符加密

func PriKeyEncrypt

func PriKeyEncrypt(data, priPEM string) ([]byte, error)

私钥加密

func PubKeyEncrypt_E_N

func PubKeyEncrypt_E_N(msg, hexE, hexN string) []byte

func PubKeyEncrypt_NoPad

func PubKeyEncrypt_NoPad(msg, hexE, hexN, reserve string) []byte

RSANoPadding,modulus为16进制字符串,仅适合0-255的字符加密

func PubKeyEncrypt_b64

func PubKeyEncrypt_b64(plainText []byte, pubBase64 string) ([]byte, error)

func Pubkey_to_pem

func Pubkey_to_pem(pubkey *rsa.PublicKey) string

输出pem格式的公钥

func PublicDecrypt

func PublicDecrypt(data []byte, pubPEM string) ([]byte, error)

公钥解密

func PublicEncrypt

func PublicEncrypt(data, pubPEM string) ([]byte, error)

公钥加密

func ReadNE

func ReadNE(hexN string, hexE string) (*rsa.PublicKey, error)

另一种创建pubkey的方法,通过N,E

func SignMd5WithRsa

func SignMd5WithRsa(data string, privateKey string) (string, error)

使用RSAWithMD5算法签名

func SignSha1WithRsa

func SignSha1WithRsa(data string, privateKey string) (string, error)

使用RSAWithSHA1算法签名

func SignSha256WithRsa

func SignSha256WithRsa(data string, privateKey string) (string, error)

使用RSAWithSHA256算法签名

func VerifySignMd5WithRsa

func VerifySignMd5WithRsa(data string, signData string, publicKey string) error

使用RSAWithMD5验证签名

func VerifySignSha1WithRsa

func VerifySignSha1WithRsa(data string, signData string, publicKey string) error

使用RSAWithSHA1验证签名

func VerifySignSha256WithRsa

func VerifySignSha256WithRsa(data string, signData string, publicKey string) error

使用RSAWithSHA256验证签名

Types

type RSASecurity

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

func (*RSASecurity) GetPrivatekey

func (rsas *RSASecurity) GetPrivatekey() (*rsa.PrivateKey, error)

*rsa.PublicKey

func (*RSASecurity) GetPublickey

func (rsas *RSASecurity) GetPublickey() (*rsa.PublicKey, error)

*rsa.PrivateKey

func (*RSASecurity) PriKeyDECRYPT

func (rsas *RSASecurity) PriKeyDECRYPT(input []byte) ([]byte, error)

私钥解密

func (*RSASecurity) PriKeyENCTYPT

func (rsas *RSASecurity) PriKeyENCTYPT(input []byte) ([]byte, error)

私钥加密

func (*RSASecurity) PubKeyDECRYPT

func (rsas *RSASecurity) PubKeyDECRYPT(input []byte) ([]byte, error)

公钥解密

func (*RSASecurity) PubKeyENCTYPT

func (rsas *RSASecurity) PubKeyENCTYPT(input []byte) ([]byte, error)

公钥加密

func (*RSASecurity) SetPrivateKey

func (rsas *RSASecurity) SetPrivateKey(priStr string) (err error)

设置私钥

func (*RSASecurity) SetPublicKey

func (rsas *RSASecurity) SetPublicKey(pubStr string) (err error)

设置公钥

func (*RSASecurity) SignMd5WithRsa

func (rsas *RSASecurity) SignMd5WithRsa(data string) (string, error)

*

  • 使用RSAWithMD5算法签名

func (*RSASecurity) SignSha1WithRsa

func (rsas *RSASecurity) SignSha1WithRsa(data string) (string, error)

*

  • 使用RSAWithSHA1算法签名

func (*RSASecurity) SignSha256WithRsa

func (rsas *RSASecurity) SignSha256WithRsa(data string) (string, error)

*

  • 使用RSAWithSHA256算法签名

func (*RSASecurity) VerifySignMd5WithRsa

func (rsas *RSASecurity) VerifySignMd5WithRsa(data string, signData string) error

*

  • 使用RSAWithMD5验证签名

func (*RSASecurity) VerifySignSha1WithRsa

func (rsas *RSASecurity) VerifySignSha1WithRsa(data string, signData string) error

*

  • 使用RSAWithSHA1验证签名

func (*RSASecurity) VerifySignSha256WithRsa

func (rsas *RSASecurity) VerifySignSha256WithRsa(data string, signData string) error

*

  • 使用RSAWithSHA256验证签名

Jump to

Keyboard shortcuts

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