Пример #1
0
        private JdPayDictionary GetEncryptDicContent <T>(IJdPayRequest <T> request, IDictionary <string, string> dic) where T : JdPayResponse
        {
            var signDic = new JdPayDictionary(dic)
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
            };

            var sign = JdPaySignature.RSASign(signDic, RSAPrivateParameters);

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

            foreach (var item in dic)
            {
                if (!string.IsNullOrEmpty(item.Value))
                {
                    encyptDic.Add(item.Key, DES3.EncryptECB(DesKey, item.Value));
                }
            }
            return(encyptDic);
        }
Пример #2
0
        private JDPayDictionary BuildEncryptDic <T>(IJDPayRequest <T> request, IDictionary <string, string> dic) where T : JDPayResponse
        {
            var signDic = new JDPayDictionary(dic)
            {
                { 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 item in dic)
            {
                if (!string.IsNullOrEmpty(item.Value))
                {
                    encyptDic.Add(item.Key, DES3.EncryptECB(item.Value, DesKey));
                }
            }
            return(encyptDic);
        }
Пример #3
0
        private string GetEncryptXmlContent <T>(IJdPayRequest <T> request, JdPayDictionary dic) where T : JdPayResponse
        {
            var xmldoc = JdPayUtil.SortedDictionary2AllXml(dic);
            var smlStr = JdPayUtil.ConvertXmlToString(xmldoc);
            var sha256SourceSignString = SHA256.Compute(smlStr);
            var encyptBytes            = JdPaySignature.Encrypt(sha256SourceSignString, RSAPrivateParameters);
            var sign    = Convert.ToBase64String(encyptBytes, Base64FormattingOptions.InsertLineBreaks);
            var data    = smlStr.Replace("</jdpay>", "<sign>" + sign + "</sign></jdpay>");
            var encrypt = DES3.EncryptECB(DesKey, data);
            // 字典排序
            var reqdic = new JdPayDictionary
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
                { ENCRYPT, Convert.ToBase64String(Encoding.UTF8.GetBytes(encrypt)) }
            };

            return(JdPayUtil.SortedDictionary2XmlStr(reqdic));
        }
Пример #4
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 = DES3.EncryptECB(data, DesKey);
            // 字典排序
            var reqdic = new JDPayDictionary
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
                { ENCRYPT, Convert.ToBase64String(Encoding.UTF8.GetBytes(encrypt)) }
            };

            return(JDPayUtility.SortedDictionary2XmlStr(reqdic));
        }