This commit is contained in:
suyl
2021-08-17 14:56:14 +08:00
parent 53a12a47b6
commit 8b62fb2bf9

View File

@@ -245,26 +245,32 @@ func NewDingTalkCrypto(token, encodingAESKey, suiteKey string) *DingTalkCrypto {
} }
func (c *DingTalkCrypto) GetDecryptMsg(signature, timestamp, nonce, secretMsg string) (string, error) { func (c *DingTalkCrypto) GetDecryptMsg(signature, timestamp, nonce, secretMsg string) (string, error) {
if !c.VerificationSignature(c.Token, timestamp, nonce, secretMsg, signature) { if !c.VerificationSignature(c.Token, timestamp, nonce, secretMsg, signature) {
fmt.Println("33333333333333333333333333333")
return "", errors.New("ERROR: 签名不匹配") return "", errors.New("ERROR: 签名不匹配")
} }
decode, err := base64.StdEncoding.DecodeString(secretMsg) decode, err := base64.StdEncoding.DecodeString(secretMsg)
if err != nil { if err != nil {
fmt.Println("1111111111111111111111", err)
return "", err return "", err
} }
if len(decode) < aes.BlockSize { if len(decode) < aes.BlockSize {
fmt.Println("2222222222222222222222222222222", err)
return "", errors.New("ERROR: 密文太短") return "", errors.New("ERROR: 密文太短")
} }
fmt.Println("1")
blockMode := cipher.NewCBCDecrypter(c.Block, c.BKey[:c.Block.BlockSize()]) blockMode := cipher.NewCBCDecrypter(c.Block, c.BKey[:c.Block.BlockSize()])
fmt.Println("2")
plantText := make([]byte, len(decode)) plantText := make([]byte, len(decode))
fmt.Println("3")
blockMode.CryptBlocks(plantText, decode) blockMode.CryptBlocks(plantText, decode)
fmt.Println("4")
plantText = pkCS7UnPadding(plantText) plantText = pkCS7UnPadding(plantText)
fmt.Println("5")
size := binary.BigEndian.Uint32(plantText[16:20]) size := binary.BigEndian.Uint32(plantText[16:20])
fmt.Println("6")
plantText = plantText[20:] plantText = plantText[20:]
fmt.Println("7")
corpID := plantText[size:] corpID := plantText[size:]
fmt.Println("8")
if string(corpID) != c.SuiteKey { if string(corpID) != c.SuiteKey {
fmt.Println("9")
return "", errors.New("ERROR: CorpID匹配不正确") return "", errors.New("ERROR: CorpID匹配不正确")
} }
fmt.Println("222222222222222222222222222222222222") fmt.Println("222222222222222222222222222222222222")