From 4e0adf45d09bdc8996c194c8407e22dab1d53707 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 28 Dec 2018 15:02:00 +0800 Subject: [PATCH] - fix SNSDecodeMiniProgramData --- platformapi/weixinapi/weixinapi.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platformapi/weixinapi/weixinapi.go b/platformapi/weixinapi/weixinapi.go index 2599cb0b..299a6c2e 100644 --- a/platformapi/weixinapi/weixinapi.go +++ b/platformapi/weixinapi/weixinapi.go @@ -290,8 +290,15 @@ func (a *API) SNSDecodeMiniProgramData(encryptedData, sessionKey, iv string) (de if err != nil { return nil, err } - cfbdec := cipher.NewCFBDecrypter(c, decodedDataList[2]) + cfbdec := cipher.NewCBCDecrypter(c, decodedDataList[2][:c.BlockSize()]) decryptedData = make([]byte, len(decodedDataList[0])) - cfbdec.XORKeyStream(decryptedData, decodedDataList[0]) + cfbdec.CryptBlocks(decryptedData, decodedDataList[0]) + decryptedData = PKCS7UnPadding(decryptedData) return decryptedData, nil } + +func PKCS7UnPadding(origData []byte) []byte { + length := len(origData) + unpadding := int(origData[length-1]) + return origData[:(length - unpadding)] +}