/// <summary> /// Writes a byte array to the specified <see cref="HttpListenerResponse"/>. /// </summary> /// <param name="data">The array of bytes to send.</param> /// <param name="statusCode">The <see cref="HttpStatusCode"/> to send to the client.</param> /// <remarks> /// This method also automatically encrypts the outgoing data if the request contained an IV and session id. /// </remarks> public override void Send(byte[] data, HttpStatusCode statusCode = HttpStatusCode.OK) { if (data != null && Utils.IsRequestEncrypted(Request)) { Response.StatusCode = (int)statusCode; Response.ContentType = "application/octet-stream"; // Encode data and add IV header var sessionId = Request.Cookies["session"].Value; data = Utils.AESEncrypt(sessionId, data, out byte[] iv); Response.AddHeader("Content-IV", Convert.ToBase64String(iv)); } base.Send(data, statusCode); // Write detailed log about response var logMessage = $"Processed {Request.HttpMethod} request for '{Request.Url.AbsolutePath}' with status code {(int)statusCode} " + $"in {Utils.FormatTimer(Timer)}{(data == null ? "" : $" and sent {Utils.FormatDataLength(data.Length)}")}."; // Success status codes are seen as less important, thus are trace messages if (((int)statusCode).ToString().StartsWith("2")) { Program.Log.Trace(logMessage); } else { Program.Log.Info(logMessage); } }
/// <summary> /// 将表单转为Json /// </summary> /// <param name="dataSets"></param> public static void ConvertDataSetToJson(List <DataSet> dataSets) { Encoding encoding = Encoding.UTF8; foreach (var dataSet in dataSets) { //生成Json字符串 string json = Newtonsoft.Json.JsonConvert.SerializeObject(dataSet, Newtonsoft.Json.Formatting.Indented); if (!Directory.Exists(jsonOutputPath)) { Directory.CreateDirectory(jsonOutputPath); } #if ENCRYPT string enJson = Utils.AESEncrypt(json); #else string enJson = json; #endif //写入文件 using (FileStream fileStream = new FileStream(jsonOutputPath + "/" + dataSet.DataSetName.ToLower() + ".json", FileMode.Create, FileAccess.Write)) { using (TextWriter textWriter = new StreamWriter(fileStream, encoding)) { textWriter.Write(enJson); } } } }
public static List <T> Load <T>(string fileName) where T : class { Type type = typeof(T); if (!type.IsDefined(typeof(System.SerializableAttribute), true)) { Debuger.LogError(type.Name + " doesn't has the SerializableAttribute." + "please add it!"); } #if ENCRYPT string encrptName = Utils.AESEncrypt(fileName); TextAsset jsonText = Resources.Load <TextAsset>("Jsons\\" + encrptName); string decryptJson = Utils.AESDecrypt(jsonText.text); #else string encrptName = fileName; TextAsset jsonText = Resources.Load <TextAsset>("Jsons\\" + encrptName); string decryptJson = ""; try { decryptJson = jsonText.text; } catch (NullReferenceException) { Debug.LogError("Json Read Name Is Null By " + encrptName); return(null); } #endif return(JsonUtility.FromJson <JsonStructure <T> >(decryptJson).data); }
private string Encrypt(string value) { return(Utils.AESEncrypt(value, _symmetricKey)); }
private string Encrypt(string value) { //return string.Format("convert(nvarchar(512),convert(varbinary(512),{0}),1)", value); return(Utils.AESEncrypt(value, _symmetricKey)); }