Пример #1
0
        private JDPayDictionary BuildEncryptDic <T>(IJDPayRequest <T> request, IDictionary <string, string> parameters) where T : JDPayResponse
        {
            var signDic = new JDPayDictionary(parameters)
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
            };

            var signContent = JDPaySecurity.GetSignContent(signDic);
            var sign        = JDPaySecurity.RSASign(signContent, PrivateKey);

            var encyptDic = new JDPayDictionary
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
                { SIGN, sign }
            };

            foreach (var iter in parameters)
            {
                if (!string.IsNullOrEmpty(iter.Value))
                {
                    encyptDic.Add(iter.Key, JDPaySecurity.EncryptECB(iter.Value, DesKey));
                }
            }
            return(encyptDic);
        }
Пример #2
0
        private JDPayDictionary BuildEncryptDic <T>(IJDPayRequest <T> request, IDictionary <string, string> dictionary, JDPayOptions options) where T : JDPayResponse
        {
            var signDic = new JDPayDictionary(dictionary)
            {
                { JDPayContants.VERSION, request.GetApiVersion() },
                { JDPayContants.MERCHANT, options.Merchant }
            };

            var signContent = JDPaySecurity.GetSignContent(signDic);
            var sign        = JDPaySecurity.RSASign(signContent, options.PrivateKey);

            var encyptDic = new JDPayDictionary
            {
                { JDPayContants.VERSION, request.GetApiVersion() },
                { JDPayContants.MERCHANT, options.Merchant },
                { JDPayContants.SIGN, sign }
            };

            foreach (var iter in dictionary)
            {
                if (!string.IsNullOrEmpty(iter.Value))
                {
                    encyptDic.Add(iter.Key, JDPaySecurity.EncryptECB(iter.Value, options.DesKeyBase64));
                }
            }
            return(encyptDic);
        }
Пример #3
0
        private string BuildEncryptXml <T>(IJDPayRequest <T> request, JDPayDictionary dic) where T : JDPayResponse
        {
            var xmldoc = JDPayUtility.SortedDictionary2AllXml(dic);
            var smlStr = JDPayUtility.ConvertXmlToString(xmldoc);
            var sha256SourceSignString = SHA256.Compute(smlStr);
            var encyptBytes            = RSA_ECB_PKCS1Padding.Encrypt(Encoding.UTF8.GetBytes(sha256SourceSignString), PrivateKey);
            var sign    = Convert.ToBase64String(encyptBytes, Base64FormattingOptions.InsertLineBreaks);
            var data    = smlStr.Replace("</jdpay>", "<sign>" + sign + "</sign></jdpay>");
            var encrypt = JDPaySecurity.EncryptECB(data, DesKey);
            // 字典排序
            var reqdic = new JDPayDictionary
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
                { ENCRYPT, Convert.ToBase64String(Encoding.UTF8.GetBytes(encrypt)) }
            };

            return(JDPayUtility.SortedDictionary2XmlStr(reqdic));
        }