encryptor

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInvalidSignature = -40001 // Signature verification failed
	ErrParseXml         = -40002 // Parse XML failed
	ErrCalcSignature    = -40003 // Calculating the signature failed
	ErrInvalidAesKey    = -40004 // Invalid AESKey
	ErrInvalidAppID     = -40005 // Check AppID failed
	ErrEncryptAes       = -40006 // AES EncryptionInterface failed
	ErrDecryptAes       = -40007 // AES decryption failed
	ErrInvalidXml       = -40008 // Invalid XML
	ErrBase64Encode     = -40009 // Base64 encoding failed
	ErrBase64Decode     = -40010 // Base64 decoding failed
	ErrXmlBuild         = -40011 // XML build failed
	ErrIllegalBuffer    = -41003 // Illegal buffer
)

Variables

This section is empty.

Functions

func PKCS7Pad

func PKCS7Pad(message []byte, blockSize int) (padded []byte)

func PadLength

func PadLength(sliceLength, blockSize int) (padLen int)

PadLength calculates padding length, from github.com/vgorin/cryptogo

Types

type CDATAText

type CDATAText struct {
	Text string `xml:",innerxml"`
}

CDATAText 文本域

type EncryptRequestBody

type EncryptRequestBody struct {
	XMLName    xml.Name `xml:"xml"`
	ToUserName string
	Encrypt    string
}

EncryptRequestBody 加密消息

type EncryptResponseBody

type EncryptResponseBody struct {
	XMLName      xml.Name `xml:"xml"`
	Encrypt      CDATAText
	MsgSignature CDATAText
	TimeStamp    string
	Nonce        CDATAText
}

EncryptResponseBody 加密回复消息

type Encryptor

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

func NewEncryptor

func NewEncryptor(appId, token, aesKey string) *Encryptor

func (*Encryptor) AesDecrypt

func (e *Encryptor) AesDecrypt(cipherData []byte) ([]byte, error)

AesDecrypt 解密

func (*Encryptor) AesEncrypt

func (e *Encryptor) AesEncrypt(plainData []byte) ([]byte, error)

AesEncrypt 加密

func (*Encryptor) MakeEncryptBody

func (e *Encryptor) MakeEncryptBody(xmlBody []byte, timestamp, nonce string) ([]byte, error)

MakeEncryptBody 构建加密消息体

func (*Encryptor) ParseEncryptBody

func (e *Encryptor) ParseEncryptBody(r *http.Request) (*EncryptRequestBody, error)

ParseEncryptBody 解析加密消息数据

func (*Encryptor) ParseEncryptTextBody

func (e *Encryptor) ParseEncryptTextBody(plainText []byte) (*message.Message, error)

func (*Encryptor) ParseTextBody

func (e *Encryptor) ParseTextBody(r *http.Request) (*message.Message, error)

ParseTextBody 解析文本消息数据

func (*Encryptor) ValidAppId

func (e *Encryptor) ValidAppId(id []byte) bool

func (*Encryptor) ValidMsgSignature

func (e *Encryptor) ValidMsgSignature(timestamp, nonce, msgEncrypt, signature string) bool

ValidMsgSignature 验证消息签名

func (*Encryptor) ValidSignature

func (e *Encryptor) ValidSignature(timestamp, nonce, signature string) bool

ValidSignature 验证Url签名

type TextResponseBody

type TextResponseBody struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   CDATAText
	FromUserName CDATAText
	CreateTime   string
	MsgType      CDATAText
	Content      CDATAText
}

TextResponseBody 文本回复消息

Jump to

Keyboard shortcuts

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