codec

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

* @Author: cnzf1 * @Date: 2021-08-05 17:31:50

  • @LastEditors: cnzf1
  • @LastEditTime: 2023-03-01 16:49:29

* @Description:

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPrivKey       = errors.New("private key error")
	ErrPubKey        = errors.New("failed to parse PEM block containing the public key")
	ErrPrivKeyNotRsa = errors.New("private key type is not RSA")
	ErrPubKeyNotRsa  = errors.New("public key type is not RSA")
)

Functions

func MarshalPKCS8PrivateKey

func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte

Types

type Crypter

type Crypter interface {
	Encrypter
	Decrypter
}

type Decrypter

type Decrypter interface {
	Decrypt(encData []byte) ([]byte, error)
	DecryptBase64(encData string) ([]byte, error)
}

Decrypter represents a RSA decrypter.

type Encrypter

type Encrypter interface {
	Encrypt(rawData []byte) ([]byte, error)
	EncryptBase64(rawData []byte) (string, error)
}

Encrypter represents a RSA encrypter.

type Rsa

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

func CreateRsa

func CreateRsa(keyLength int) (*Rsa, error)

生成pkcs1格式公钥私钥

func CreateRsaPkcs8

func CreateRsaPkcs8(keyLength int) (*Rsa, error)

生成pkcs8格式公钥私钥

func NewRsa

func NewRsa(publicKey, privateKey string) (*Rsa, error)

生成RSA对象

func (*Rsa) Decrypt

func (this *Rsa) Decrypt(encData []byte) ([]byte, error)

私钥解密

func (*Rsa) DecryptBase64

func (this *Rsa) DecryptBase64(encData string) ([]byte, error)

私钥解密+base64解码

func (*Rsa) DecryptBase64Ex

func (this *Rsa) DecryptBase64Ex(encData string) ([]byte, error)

公钥解密+base64解码

func (*Rsa) DecryptEx

func (this *Rsa) DecryptEx(encData []byte) ([]byte, error)

公钥解密

func (*Rsa) Encrypt

func (this *Rsa) Encrypt(rawData []byte) ([]byte, error)

公钥加密

func (*Rsa) EncryptBase64

func (this *Rsa) EncryptBase64(rawData []byte) (string, error)

公钥加密+base64编码

func (*Rsa) EncryptBase64Ex

func (this *Rsa) EncryptBase64Ex(rawData []byte) (string, error)

私钥加密+base64编码

func (*Rsa) EncryptEx

func (this *Rsa) EncryptEx(rawData []byte) ([]byte, error)

私钥加密

func (*Rsa) Sign

func (this *Rsa) Sign(rawData []byte, algorithmSign crypto.Hash) ([]byte, error)

私钥签名

func (*Rsa) Verify

func (this *Rsa) Verify(rawData []byte, sign []byte, algorithmSign crypto.Hash) bool

公钥验签

type Signer

type Signer interface {
	Sign(rawData []byte, algorithmSign crypto.Hash) ([]byte, error)
	Verify(rawData []byte, sign []byte, algorithmSign crypto.Hash) bool
}

Jump to

Keyboard shortcuts

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