添加处理服务器发送信息逻辑
添加tcp逻辑错误的处理
This commit is contained in:
commit
c6e55c166c
4 files changed
+90
-29
No files matched your search
@@ -9,13 +9,13 @@ namespace SunlightAggregationTerminal.Class
|
||||
{
|
||||
public class SecureJsonService
|
||||
{
|
||||
private readonly byte[] _aesKey = Encoding.UTF8.GetBytes("12345678901234567890123456789012");
|
||||
private static readonly byte[] _aesKey = Encoding.UTF8.GetBytes("12345678901234567890123456789012");
|
||||
|
||||
/// <summary>
|
||||
/// 调用一:发送端处理
|
||||
/// 流程:JSON序列化 -> GZip压缩 -> AES加密 -> Base64编码
|
||||
/// </summary>
|
||||
public string CompressEncryptAndSend(object dataObject)
|
||||
public static string CompressEncryptAndSend(object dataObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -35,9 +35,8 @@ namespace SunlightAggregationTerminal.Class
|
||||
|
||||
return finalPayload;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine($"发送端处理错误: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +45,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
/// 调用二:接收端处理
|
||||
/// 流程:Base64解码 -> AES解密 -> GZip解压 -> JSON反序列化
|
||||
/// </summary>
|
||||
public T? ReceiveDecryptAndDecompress<T>(string payload)
|
||||
public static T? ReceiveDecryptAndDecompress<T>(string payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -73,7 +72,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
|
||||
// --- 底层辅助方法 ---
|
||||
|
||||
private byte[] CompressBytes(byte[] data)
|
||||
private static byte[] CompressBytes(byte[] data)
|
||||
{
|
||||
using (var outputStream = new MemoryStream())
|
||||
{
|
||||
@@ -85,7 +84,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DecompressBytes(byte[] data)
|
||||
private static byte[] DecompressBytes(byte[] data)
|
||||
{
|
||||
using (var inputStream = new MemoryStream(data))
|
||||
{
|
||||
@@ -100,7 +99,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] EncryptBytes(byte[] data)
|
||||
private static byte[] EncryptBytes(byte[] data)
|
||||
{
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
@@ -126,7 +125,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DecryptBytes(byte[] data)
|
||||
private static byte[] DecryptBytes(byte[] data)
|
||||
{
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user