Ejemplo n.º 1
0
        public SignItem GetSignItem(IAopRequest <T> request, string reponseBody)
        {
            if (string.IsNullOrEmpty(reponseBody))
            {
                return(null);
            }

            SignItem signItem = new SignItem();
            string   sign     = GetSign(reponseBody);

            signItem.Sign = sign;

            string signSourceData = GetSignSourceData(request, reponseBody);

            signItem.SignSourceDate = signSourceData;

            return(signItem);
        }
Ejemplo n.º 2
0
        public static void CheckResponseSign <T>(IAopRequest <T> request, string responseBody, bool isError, IAopParser <T> parser, string alipayPublicKey, string charset, string signType, bool keyFromFile) where T : AopResponse
        {
            if (string.IsNullOrEmpty(alipayPublicKey) || string.IsNullOrEmpty(charset))
            {
                return;
            }

            SignItem signItem = parser.GetSignItem(request, responseBody);

            if (signItem == null)
            {
                throw new AopException("sign check fail: Body is Empty!");
            }

            if (!isError ||
                (isError && !string.IsNullOrEmpty(signItem.Sign)))
            {
                bool rsaCheckContent = AlipaySignature.RSACheckContent(signItem.SignSourceDate, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile);
                if (!rsaCheckContent)
                {
                    if (!string.IsNullOrEmpty(signItem.SignSourceDate) && signItem.SignSourceDate.Contains("\\/"))
                    {
                        string srouceData = signItem.SignSourceDate.Replace("\\/", "/");
                        bool   jsonCheck  = AlipaySignature.RSACheckContent(srouceData, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile);
                        if (!jsonCheck)
                        {
                            throw new AopException(
                                      "sign check fail: check Sign and Data Fail JSON also");
                        }
                    }
                    else
                    {
                        throw new AopException(
                                  "sign check fail: check Sign and Data Fail!");
                    }
                }
            }
        }