//响应平台请求 public void ResponseToServer(HttpResponse resp, IDictionary <string, object> dictionary = null) { try { //去除空字典项,并检查字典合法性 IDictionary <string, object> newDictionary = null; if (dictionary != null) { newDictionary = AopUtils.CleanupDictionary(dictionary); } ReturnToServer returnToServer = new ReturnToServer(); string httpJsonStr = JsonConvert.SerializeObject(returnToServer); if (newDictionary != null && newDictionary.Count > 0) { //构造业务参数json string dataJson = BuildBizJson(newDictionary); //数据加签RSA string sign = Signature.RSASignCharSetXML(dataJson, privateKeyPem, charset, false); //数据加密AES string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset); returnToServer.data = dataEncrypt; returnToServer.sign = sign; httpJsonStr = JsonConvert.SerializeObject(returnToServer); } //写入响应流 webUtils.WriteResponse(resp, httpJsonStr, Encoding.GetEncoding(charset)); } catch (Exception ex) { throw new AopException("响应失败,请检查业务参数"); } }
public void TestAes_2() { var encode = Encrypt.AesEncrypt("中国"); _output.WriteLine(encode); Assert.Equal("中国", Encrypt.AesDecrypt(encode)); }
public void ResponseToServer(HttpResponse resp, object jsonObj = null) { try { ReturnToServer returnToServer = new ReturnToServer(); string httpJsonStr = JsonConvert.SerializeObject(returnToServer); if (jsonObj != null) { //构造业务参数json string dataJson = JsonConvert.SerializeObject(jsonObj); //数据加签RSA string sign = Signature.RSASignCharSetXML(dataJson, privateKeyPem, charset, false); //数据加密AES string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset); returnToServer.data = dataEncrypt; returnToServer.sign = sign; httpJsonStr = JsonConvert.SerializeObject(returnToServer); } //写入响应流 webUtils.WriteResponse(resp, httpJsonStr, Encoding.GetEncoding(charset)); } catch (Exception ex) { throw new AopException("响应失败,请检查业务参数"); } }
public void Test_Aes_2() { const string value = "中国"; var encode = Encrypt.AesEncrypt(value); Output.WriteLine(encode); Assert.Equal(value, Encrypt.AesDecrypt(encode)); }
public static void WriteLoginCookie(string cliamsStr) { cliamsStr = Encrypt.AesEncrypt(cliamsStr); HttpContextExt.Current.Response.Cookies.Append(LoginCookieDto.CookieClaim, cliamsStr, new CookieOptions() { Expires = DateTime.UtcNow.AddHours(10), Path = "/", HttpOnly = false, Secure = false }); }
public void SetCookie(string cliamsString) { cliamsString = Encrypt.AesEncrypt(cliamsString); _context.Response.Cookies.Append(CookieClaim, cliamsString, new CookieOptions() { Expires = DateTime.UtcNow.AddHours(10), Path = "/", HttpOnly = false, Secure = false }); }
public void SetCookie(string key, string value, int expireSecond) { string cliamsString = Encrypt.AesEncrypt(value); _context.Response.Cookies.Append(key, cliamsString, new CookieOptions() { Expires = DateTime.UtcNow.AddSeconds(expireSecond), Path = "/", HttpOnly = false, Secure = false }); }
public void SetCookie(string cliamsString) { cliamsString = Encrypt.AesEncrypt(cliamsString); _context.Response.Cookies.Append(CookieClaim, cliamsString, new CookieOptions() { Expires = DateTime.UtcNow.AddHours(10), Path = "/", HttpOnly = false, IsEssential = true, Secure = false //Secure = true, //SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None }); }
public void SetCookie(string key, string value, int expireSecond) { string cliamsString = Encrypt.AesEncrypt(value); _context.Response.Cookies.Append(key, cliamsString, new CookieOptions() { Expires = DateTime.UtcNow.AddSeconds(expireSecond), Path = "/", HttpOnly = false, IsEssential = true, Secure = false, //Secure = true, //SameSite= Microsoft.AspNetCore.Http.SameSiteMode.None }); }
public void SaveKeyValue(string key, string value, string filename) { string v = Encrypt.AesEncrypt(key + " " + value, EncryptKeys[0]); try { using (StreamWriter sw = new StreamWriter(filename, append: false)) { sw.Write(v); } } catch (Exception ex) { Logger.LogF(ex); } }
//执行平台请求,并获取平台响应 public string RequestToServer(IDictionary <string, object> dictionary = null) { try { //去除空字典项,并检查字典合法性 IDictionary <string, object> newDictionary = null; if (dictionary != null) { newDictionary = AopUtils.CleanupDictionary(dictionary); } // 添加协议级请求参数 HttpRequestJson httpRequestJson = new HttpRequestJson { token = new PlatformToken { apiID = apiID, userID = userID, timestamp = AopUtils.GetTimestamp(DateTime.Now).ToString() } }; string httpJsonStr = JsonConvert.SerializeObject(httpRequestJson); if (newDictionary != null && newDictionary.Count > 0) { //构造业务参数json string dataJson = BuildBizJson(newDictionary); //数据加签RSA var tokenStr = JsonConvert.SerializeObject(httpRequestJson.token); string sign = Signature.RSASignCharSetXML(dataJson + tokenStr, privateKeyPem, charset, false); //数据加密AES string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset); httpRequestJson.data = dataEncrypt; httpRequestJson.sign = sign; httpJsonStr = JsonConvert.SerializeObject(httpRequestJson); } string result = Excute(httpJsonStr); return(result); } catch (Exception ex) { return(null); } }
public static void WriteLoginCookie(string cliamsStr) { //var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(LoginCookieDto.CookieClaim, cliamsStr) }, "Forms"); //var userPrincipal = new ClaimsPrincipal(claimsIdentity); //HttpContextExt.Current.SignInAsync(LoginCookieDto.CookieScheme, userPrincipal, new AuthenticationProperties //{ // ExpiresUtc = DateTime.UtcNow.AddHours(10), // IsPersistent = true, // AllowRefresh = false //}); cliamsStr = Encrypt.AesEncrypt(cliamsStr); HttpContextExt.Current.Response.Cookies.Append(LoginCookieDto.CookieClaim, cliamsStr, new CookieOptions() { Expires = DateTime.UtcNow.AddHours(10), Path = "/", HttpOnly = false, Secure = false }); }
public string RequestToServer(object jsonObj = null) { try { // 添加协议级请求参数 HttpRequestJson httpRequestJson = new HttpRequestJson { token = new PlatformToken { apiID = apiID, userID = userID, timestamp = AopUtils.GetTimestamp(DateTime.Now).ToString() } }; string httpJsonStr = JsonConvert.SerializeObject(httpRequestJson); if (jsonObj != null) { //构造业务参数json string dataJson = JsonConvert.SerializeObject(jsonObj); //数据加签RSA var tokenStr = JsonConvert.SerializeObject(httpRequestJson.token); string sign = Signature.RSASignCharSetXML(dataJson + tokenStr, privateKeyPem, charset, false); //数据加密AES string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset); httpRequestJson.data = dataEncrypt; httpRequestJson.sign = sign; httpJsonStr = JsonConvert.SerializeObject(httpRequestJson); } string result = Excute(httpJsonStr); return(result); } catch (Exception ex) { return(null); } }
public void TestAes_Validate(string input, string key, string result) { Assert.Equal(result, Encrypt.AesEncrypt(input, key, Encoding.UTF8)); Assert.Equal(result, Encrypt.AesDecrypt(input, key, Encoding.UTF8)); }