Пример #1
0
        private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode)
        {
            int signDataStartIndex = indexOfRootNode + rootNode.Length + 2;
            int indexOfSign        = body.IndexOf("\"" + AlipayConstants.SIGN + "\"", StringComparison.Ordinal);

            int signDataEndIndex = indexOfSign - 1;

            if (signDataEndIndex < 0)
            {
                signDataEndIndex = body.Length - 1;
            }

            int length = signDataEndIndex - signDataStartIndex;

            string encyptContent = body.Substring(signDataStartIndex + 1, length - 2);

            EncryptParseItem item = new EncryptParseItem();

            item.encryptContent = encyptContent;
            item.startIndex     = signDataStartIndex;
            item.endIndex       = signDataEndIndex;


            return(item);
        }
Пример #2
0
        private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode)
        {
            //  第一个字母+长度+>
            int signDataStartIndex = indexOfRootNode + rootNode.Length + 1;

            string xmlStartNode       = "<" + AlipayConstants.ENCRYPT_NODE_NAME + ">";
            string xmlEndNode         = "</" + AlipayConstants.ENCRYPT_NODE_NAME + ">";
            int    indexOfEncryptNode = body.IndexOf(xmlEndNode);

            if (indexOfEncryptNode < 0)
            {
                EncryptParseItem item = new EncryptParseItem();
                item.encryptContent = null;
                item.startIndex     = 0;
                item.endIndex       = 0;

                return(item);
            }

            int startIndex = signDataStartIndex + xmlStartNode.Length;
            int bizLen     = indexOfEncryptNode - startIndex;

            string encryptBizContent = body.Substring(startIndex, bizLen);

            EncryptParseItem item2 = new EncryptParseItem();

            item2.encryptContent = encryptBizContent;
            item2.startIndex     = signDataStartIndex;
            item2.endIndex       = indexOfEncryptNode + xmlEndNode.Length;

            return(item2);
        }
Пример #3
0
        private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode)
        {
            int    num   = indexOfRootNode + rootNode.Length + 1;
            string text  = "<response_encrypted>";
            string text2 = "</response_encrypted>";
            int    num2  = body.IndexOf(text2);

            if (num2 < 0)
            {
                EncryptParseItem encryptParseItem = new EncryptParseItem();
                encryptParseItem.encryptContent = null;
                encryptParseItem.startIndex     = 0;
                encryptParseItem.endIndex       = 0;
                return(encryptParseItem);
            }
            int              num3              = num + text.Length;
            int              length            = num2 - num3;
            string           encryptContent    = body.Substring(num3, length);
            EncryptParseItem encryptParseItem2 = new EncryptParseItem();

            encryptParseItem2.encryptContent = encryptContent;
            encryptParseItem2.startIndex     = num;
            encryptParseItem2.endIndex       = num2 + text2.Length;
            return(encryptParseItem2);
        }
Пример #4
0
        public string EncryptSourceData(IAopRequest <T> request, string body, string encryptType, string encryptKey, string charset)
        {
            EncryptParseItem encryptParseItem = ParseEncryptData(request, body);
            string           str  = body.Substring(0, encryptParseItem.startIndex);
            string           str2 = body.Substring(encryptParseItem.endIndex);
            string           str3 = AlipayEncrypt.AesDencrypt(encryptKey, encryptParseItem.encryptContent, charset);

            return(str + str3 + str2);
        }
Пример #5
0
        public string EncryptSourceData(IAopRequest <T> request, string body, string encryptType, string encryptKey, string charset)
        {
            EncryptParseItem item = ParseEncryptData(request, body);

            string bodyIndexContent = body.Substring(0, item.startIndex);
            string bodyEndContent   = body.Substring(item.endIndex);
            string encryptContent   = AlipayEncrypt.AesDencrypt(encryptKey, item.encryptContent, charset);

            return(bodyIndexContent + encryptContent + bodyEndContent);
        }
        public string EncryptSourceData(IAopRequest <T> request, string body, string encryptType, string encryptKey, string charset)
        {
            if (!"AES".Equals(encryptType))
            {
                throw new AopException("API only support AES!");
            }
            EncryptParseItem encryptParseItem = parseEncryptData(request, body);
            string           str  = body.Substring(0, encryptParseItem.startIndex);
            string           str2 = body.Substring(encryptParseItem.endIndex);
            string           str3 = AlipayEncrypt.AesDencrypt(encryptKey, encryptParseItem.encryptContent, charset);

            return(str + str3 + str2);
        }
Пример #7
0
        public string EncryptSourceData(IAopRequest <T> request, string body, string encryptType, string encryptKey, string charset)
        {
            if (!"AES".Equals(encryptType))
            {
                throw new AopException("API only support AES!");
            }

            EncryptParseItem item = parseEncryptData(request, body);

            string bodyIndexContent = body.Substring(0, item.startIndex);
            string bodyEndexContent = body.Substring(item.endIndex);

            //TODO 解密逻辑
            string bizContent = AlipayEncrypt.AesDencrypt(encryptKey, item.encryptContent, charset);

            return(bodyIndexContent + bizContent + bodyEndexContent);
        }
Пример #8
0
        private static EncryptParseItem ParseEncryptData(IAopRequest <T> request, string body)
        {
            string           text   = request.GetApiName().Replace(".", "_") + "_response";
            string           text2  = "error_response";
            int              num    = body.IndexOf(text);
            int              num2   = body.IndexOf(text2);
            EncryptParseItem result = null;

            if (num > 0)
            {
                result = ParseEncryptItem(body, text, num);
            }
            else if (num2 > 0)
            {
                result = ParseEncryptItem(body, text2, num2);
            }
            return(result);
        }
        private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode)
        {
            int num  = indexOfRootNode + rootNode.Length + 2;
            int num2 = body.IndexOf("\"sign\"");
            int num3 = num2 - 1;

            if (num3 < 0)
            {
                num3 = body.Length - 1;
            }
            int              num4             = num3 - num;
            string           encryptContent   = body.Substring(num + 1, num4 - 2);
            EncryptParseItem encryptParseItem = new EncryptParseItem();

            encryptParseItem.encryptContent = encryptContent;
            encryptParseItem.startIndex     = num;
            encryptParseItem.endIndex       = num3;
            return(encryptParseItem);
        }
Пример #10
0
        /// <summary>
        /// 解析加密节点
        /// </summary>
        /// <param name="request"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        private static EncryptParseItem parseEncryptData(IAopRequest <T> request, string body)
        {
            string rootNode      = request.GetApiName().Replace(".", "_") + AlipayConstants.RESPONSE_SUFFIX;
            string errorRootNode = AlipayConstants.ERROR_RESPONSE;

            int indexOfRootNode  = body.IndexOf(rootNode, StringComparison.Ordinal);
            int indexOfErrorRoot = body.IndexOf(errorRootNode, StringComparison.Ordinal);

            EncryptParseItem result = null;

            if (indexOfRootNode > 0)
            {
                result = ParseEncryptItem(body, rootNode, indexOfRootNode);
            }
            else if (indexOfErrorRoot > 0)
            {
                result = ParseEncryptItem(body, errorRootNode, indexOfErrorRoot);
            }

            return(result);
        }