/// <summary> /// 解密 /// </summary> /// <param name="model"></param> /// <returns></returns> public Task <JsonResult> DecryptData([FromBody] SecretKey model) { RSAHelper rsaHelper = new RSAHelper(); //加密解密过程中需采用 64进制编码字段 进行传递 var buffer = RSAHelper.ToStringByte(model.StringData); //设置私钥配置 RSAParameters privateParameters = RSAHelper.ToRSAParameters(model.PrivateKey); //解密 var decryptDataByte = rsaHelper.DecryptData(buffer, privateParameters, model.RsaEncryptionPadding); //出参需采用如下方式转换成正常的字符串返回 string decryptData = System.Text.Encoding.Default.GetString(decryptDataByte); //该方式效果同上 //string decryptData = System.Text.Encoding.GetEncoding("utf-8").GetString(decryptDataByte); return(Task.FromResult(Json(decryptData))); }
/// <summary> /// 内部方法 /// </summary> private async static Task <string> GetConnectionStrInner(string oauthUrl, string project, string deKey) { try { var client = HttpClientProvider.CreateHttpClient(oauthUrl); var resp = await client.GetAsync(string.Format("/api/Config/GetConStr/?project={0}", project)); if (resp.IsSuccessStatusCode) { var resultData = resp.Content.ReadAsByteArrayAsync().Result; if (resultData != null && resultData.Length > 0) { var data = RSAHelper.DecryptData(deKey, resultData); return(Encoding.UTF8.GetString(data)); } } } catch { } return(null); }