private async Task <JDPayDictionary> GetParametersAsync(HttpRequest request) { var parameters = new JDPayDictionary(); if (request.Method == "POST") { var form = await request.ReadFormAsync(); foreach (var iter in form) { if (!string.IsNullOrEmpty(iter.Value)) { parameters.Add(iter.Key, iter.Key == SIGN ? iter.Value.ToString() : JDPaySecurity.DecryptECB(iter.Value, DesKey)); } } } else { foreach (var iter in request.Query) { if (!string.IsNullOrEmpty(iter.Value)) { parameters.Add(iter.Key, iter.Key == SIGN ? iter.Value.ToString() : JDPaySecurity.DecryptECB(iter.Value, DesKey)); } } } return(parameters); }
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); }
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); }
private async Task <JDPayDictionary> GetParametersAsync(HttpRequest request) { var parameters = new JDPayDictionary(); var form = await request.ReadFormAsync(); foreach (var item in form) { parameters.Add(item.Key, item.Key.Equals(SIGN) ? item.Value.ToString() : DES3.DecryptECB(item.Value, DesKey)); } return(parameters); }
private JDPayDictionary GetParameters(HttpRequest request, bool isDecrypt = true) { var parameters = new JDPayDictionary(); if (request.Method == "POST") { foreach (var iter in request.Form) { if (!string.IsNullOrEmpty(iter.Value)) { var value = iter.Value.ToString(); if (isDecrypt) { value = iter.Key == JDPayContants.SIGN ? iter.Value.ToString() : JDPaySecurity.DecryptECB(iter.Value, Options.DesKeyBase64); } parameters.Add(iter.Key, value); } } } else { foreach (var iter in request.Query) { if (!string.IsNullOrEmpty(iter.Value)) { var value = iter.Value.ToString(); if (isDecrypt) { value = iter.Key == JDPayContants.SIGN ? iter.Value.ToString() : JDPaySecurity.DecryptECB(iter.Value, Options.DesKeyBase64); } parameters.Add(iter.Key, value); } } } return(parameters); }