1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-07 06:02:26 +08:00
This commit is contained in:
houseme
2024-07-19 12:04:04 +08:00
parent ba0a1477eb
commit d8fde54f2d
118 changed files with 974 additions and 867 deletions

View File

@@ -44,7 +44,7 @@ func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []by
func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphertext []byte) {
const (
BlockSize = 32 // PKCS#7
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时, 可以用 mask 获取针对 BLOCK_SIZE 的余数
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时可以用 mask 获取针对 BLOCK_SIZE 的余数
)
appIDOffset := 20 + len(rawXMLMsg)
@@ -100,7 +100,7 @@ func DecryptMsg(appID, encryptedMsg, aesKey string) (random, rawMsgXMLBytes []by
return
}
if appID != string(getAppIDBytes) {
err = fmt.Errorf("消息解密校验APPID失败")
err = fmt.Errorf("消息解密校验 APPID 失败")
return
}
return
@@ -127,7 +127,7 @@ func aesKeyDecode(encodedAESKey string) (key []byte, err error) {
func AESDecryptMsg(ciphertext []byte, aesKey []byte) (random, rawXMLMsg, appID []byte, err error) {
const (
BlockSize = 32 // PKCS#7
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时, 可以用 mask 获取针对 BLOCK_SIZE 的余数
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时可以用 mask 获取针对 BLOCK_SIZE 的余数
)
if len(ciphertext) < BlockSize {

View File

@@ -17,15 +17,15 @@ import (
"golang.org/x/crypto/pkcs12"
)
// URIModifier URI修改器
// URIModifier URI 修改器
type URIModifier func(uri string) string
var uriModifier URIModifier
// DefaultHTTPClient 默认httpClient
// DefaultHTTPClient 默认 httpClient
var DefaultHTTPClient = http.DefaultClient
// SetURIModifier 设置URI修改器
// SetURIModifier 设置 URI 修改器
func SetURIModifier(fn URIModifier) {
uriModifier = fn
}

View File

@@ -5,7 +5,7 @@ import (
"strings"
)
// Query 将Map序列化为Query参数
// Query 将 Map 序列化为 Query 参数
func Query(params map[string]interface{}) string {
finalString := make([]string, 0)
for key, value := range params {

View File

@@ -25,7 +25,10 @@ func RSADecrypt(privateKey string, ciphertext []byte) ([]byte, error) {
}
switch t := key.(type) {
case *rsa.PrivateKey:
priv = key.(*rsa.PrivateKey)
var ok bool
if priv, ok = key.(*rsa.PrivateKey); !ok {
return nil, fmt.Errorf(" ParsePKCS8PrivateKey error: Not supported privatekey format, should be *rsa.PrivateKey, got %T", t)
}
default:
return nil, fmt.Errorf("ParsePKCS1PrivateKey error: %s, ParsePKCS8PrivateKey error: Not supported privatekey format, should be *rsa.PrivateKey, got %T", oldErr.Error(), t)
}
@@ -33,7 +36,7 @@ func RSADecrypt(privateKey string, ciphertext []byte) ([]byte, error) {
return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)
}
// RSADecryptBase64 Base64解码后再次进行RSA解密
// RSADecryptBase64 Base64 解码后再次进行 RSA 解密
func RSADecryptBase64(privateKey string, cryptoText string) ([]byte, error) {
encryptedData, err := base64.StdEncoding.DecodeString(cryptoText)
if err != nil {

View File

@@ -7,7 +7,7 @@ import (
"sort"
)
// Signature sha1签名
// Signature sha1 签名
func Signature(params ...string) string {
sort.Strings(params)
h := sha1.New()

View File

@@ -5,7 +5,7 @@ import (
"strings"
)
// Template 对字符串中的和mapkey相同的字符串进行模板替换 仅支持 形如: {name}
// Template 对字符串中的和 mapkey 相同的字符串进行模板替换 仅支持 形如{name}
func Template(source string, data map[string]interface{}) string {
sourceCopy := &source
for k, val := range data {