algorithm

package
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Zlib Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToMd5

func BytesToMd5(data []byte) string

func FileToMd5

func FileToMd5(src io.Reader) string

func FileToMd5Byte

func FileToMd5Byte(src io.Reader) []byte

func FnvSum64 added in v0.5.36

func FnvSum64(key string) uint64

FnvSum64 gets the string and returns its uint64 hash value.

func Sha1

func Sha1(s string) (string, error)

func SignWithSha1

func SignWithSha1(sep string, s ...string) (string, error)

func StringToMd5

func StringToMd5(data string) string

Types

type Crypt

type Crypt struct {
	Token  string
	AesKey []byte
}

Crypt *

  • 1.第三方回复加密消息给公众平台;
  • 2.第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。

func NewCrypt

func NewCrypt(token, aesKey string) *Crypt

NewCrypt *

  • 构造函数
  • @param $token string 公众平台上,开发者设置的token
  • @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey
  • @param $appId string 公众平台的appId

func (*Crypt) Decrypt

func (ct *Crypt) Decrypt(signature, timestamp, nonce, encrypt string) ([]byte, error)

Decrypt *

  • 检验消息的真实性,并且获取解密后的明文.
  • <ol>
  • <li>利用收到的密文生成安全签名,进行签名验证</li>
  • <li>若验证通过,则提取xml中的加密消息</li>
  • <li>对消息进行解密</li>
  • </ol> *
  • @param signature string 签名串,对应URL参数的msg_signature
  • @param timestamp string 时间戳 对应URL参数的timestamp
  • @param nonce string 随机串,对应URL参数的nonce
  • @param encrypt string 密文 *

func (*Crypt) DecryptMsg

func (ct *Crypt) DecryptMsg(signature, timestamp, nonce, encrypt string) ([]byte, string, error)

DecryptMsg *

  • @return @string 正文 @string appid @error

func (*Crypt) Encrypt

func (ct *Crypt) Encrypt(msg, timestamp, nonce string) (string, string, error)

Encrypt *

  • 将公众平台回复用户的消息加密打包.
  • <ol>
  • <li>对要发送的消息进行AES-CBC加密</li>
  • <li>生成安全签名</li>
  • <li>将消息密文和安全签名打包成xml格式</li>
  • </ol> *
  • @param msg string 公众平台待回复用户的消息,xml格式的字符串
  • @param timeStamp string 时间戳,可以自己生成,也可以用URL参数的timestamp
  • @param nonce string 随机串,可以自己生成,也可以用URL参数的nonce *

func (*Crypt) GenerateXmlMsg

func (ct *Crypt) GenerateXmlMsg(msg, timestamp, nonce string) string

GenerateXmlMsg *

  • 生成xml消息
  • @param string $encrypt 加密后的消息密文
  • @param string $signature 安全签名
  • @param string $timestamp 时间戳
  • @param string $nonce 随机字符串

type PKCS

type PKCS interface {
	Encrypt(raw, key []byte) (string, error)
	Decrypt(raw string, key []byte) ([]byte, error)
}

func NewPKCS

func NewPKCS(ver int) PKCS

type PKCS1

type PKCS1 struct {
}

PKCS1 for rsa

func NewPKCS1

func NewPKCS1() *PKCS1

func (*PKCS1) Decrypt

func (pk *PKCS1) Decrypt(raw string, key []byte) ([]byte, error)

Decrypt PKCS interface

func (*PKCS1) Encrypt

func (pk *PKCS1) Encrypt(raw, key []byte) (string, error)

Encrypt PKCS interface

type PKCS7

type PKCS7 struct {
}

PKCS7 for aes

func NewPKCS7

func NewPKCS7() *PKCS7

func (*PKCS7) Decrypt

func (pk *PKCS7) Decrypt(raw string, key []byte) ([]byte, error)

Decrypt PKCS interface

func (*PKCS7) DecryptIv

func (pk *PKCS7) DecryptIv(raw string, aesKey []byte, iv []byte) ([]byte, error)

DecryptIv 带IV

func (*PKCS7) Encrypt

func (pk *PKCS7) Encrypt(raw, key []byte) (string, error)

Encrypt PKCS interface

func (*PKCS7) EncryptIv added in v0.5.41

func (pk *PKCS7) EncryptIv(raw string, aesKey []byte, iv []byte) ([]byte, error)

EncryptIv 带IV

Jump to

Keyboard shortcuts

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