当前位置:首页 > Windows程序 > 正文

不希望其他用户看到

2024-03-31 Windows程序

  接口返回的数据,存在一些敏感信息,不但愿其他用户看到,将Data进行加密传输

代码如下:

public class EncryptDataFilterAttribute : ActionFilterAttribute { public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { base.OnActionExecuted(actionExecutedContext); var actionList=actionExecutedContext.ActionContext.ActionDescriptor.GetCustomAttributes<EncryptDataAttribute>(); var controllList= actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes<EncryptDataAttribute>(); if (actionList.Any()||controllList.Any()) { if (((System.Net.Http.ObjectContent)actionExecutedContext.Response.Content).Value is AjaxResCode) { AjaxResCode result = actionExecutedContext.Response.Content.ReadAsAsync<AjaxResCode>().Result; if (result.Data!=null&&!string.IsNullOrWhiteSpace(result.Data.ToString())) { string data= Newtonsoft.Json.JsonConvert.SerializeObject(result.Data); //数据加密过程 result.Data = AesEncrypt.Encrypt(data, "123456"); string res = Newtonsoft.Json.JsonConvert.SerializeObject(result); HttpResponseMessage response = new HttpResponseMessage { Content = new StringContent(res, Encoding.GetEncoding("UTF-8"), "application/json") }; actionExecutedContext.Response = response; } } } } }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/35014.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494590访问次数
  • 建站天数
  • 友情链接