Beispiel #1
0
        private string ToXml(FrameDLRObject obj)
        {
            XmlDocument doc  = ComFunc.GetSafeXmlInstance();
            XmlElement  root = doc.CreateElement("xml");

            doc.AppendChild(root);
            foreach (var k in obj.Keys)
            {
                ToXmlElem(doc, root, k, obj.GetValue(k));
            }
            return(doc.InnerXml);
        }
Beispiel #2
0
        // 检验消息的真实性,并且获取解密后的明文
        // @param sMsgSignature: 签名串,对应URL参数的msg_signature
        // @param sTimeStamp: 时间戳,对应URL参数的timestamp
        // @param sNonce: 随机串,对应URL参数的nonce
        // @param sPostData: 密文,对应POST请求的数据
        // @param sMsg: 解密后的原文,当return返回0时有效
        // @return: 成功0,失败返回对应的错误码
        public WXBizMsgCryptErrorCode DecryptMsg(string sMsgSignature, string sTimeStamp, string sNonce, string sPostData, ref string sMsg)
        {
            if (m_sEncodingAESKey.Length != 43)
            {
                return(WXBizMsgCryptErrorCode.WXBizMsgCrypt_IllegalAesKey);
            }
            XmlDocument doc = ComFunc.GetSafeXmlInstance();
            XmlNode     root;
            string      sEncryptMsg;

            try
            {
                doc.LoadXml(sPostData);
                root        = doc.FirstChild;
                sEncryptMsg = root["Encrypt"].InnerText;
            }
            catch (Exception)
            {
                return(WXBizMsgCryptErrorCode.WXBizMsgCrypt_ParseXml_Error);
            }
            //verify signature
            WXBizMsgCryptErrorCode ret = 0;

            ret = VerifySignature(m_sToken, sTimeStamp, sNonce, sEncryptMsg, sMsgSignature);
            if (ret != 0)
            {
                return(ret);
            }
            //decrypt
            string cpid = "";

            try
            {
                sMsg = Cryptography.AES_decrypt(sEncryptMsg, m_sEncodingAESKey, ref cpid);
            }
            catch (FormatException)
            {
                return(WXBizMsgCryptErrorCode.WXBizMsgCrypt_DecodeBase64_Error);
            }
            catch (Exception)
            {
                return(WXBizMsgCryptErrorCode.WXBizMsgCrypt_DecryptAES_Error);
            }
            if (cpid != m_sAppID)
            {
                return(WXBizMsgCryptErrorCode.WXBizMsgCrypt_ValidateAppid_Error);
            }
            return(0);
        }