Пример #1
0
        /// <summary>
        /// 加密发往客户端的响应
        /// </summary>
        /// <param name="response">未加密的响应</param>
        /// <returns>加密后的响应</returns>
        public async Task <HttpResponse> EncryptResponse(HttpResponse response)
        {
            if (_encryptor == null || !response.IsSuccessStatusCode())
            {
                return(response);
            }

            string data = await response.ReadAsStringAsync();

            if (string.IsNullOrEmpty(data))
            {
                return(response);
            }

            try
            {
                data     = _encryptor.EncryptData(data);
                response = await response.WriteBodyAsync(data);

                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError("服务器对返回数据进行加密处理时发生异常", ex);
                throw;
            }
        }
 public string Encrypt(string data)
 {
     return(_cryptor.EncryptData(data));
 }