57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Runtime.Serialization.Json;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using CsharpHttpHelper;
|
|||
|
namespace Chat.Packet
|
|||
|
{
|
|||
|
public class PacketData
|
|||
|
{
|
|||
|
public PacketData() { }
|
|||
|
|
|||
|
public PackCMD Cmd { get; set; }
|
|||
|
public string FromUser { get; set; }
|
|||
|
|
|||
|
public object Data { get; set; }
|
|||
|
public PacketData(PackCMD cmd)
|
|||
|
{
|
|||
|
this.Cmd = cmd;
|
|||
|
}
|
|||
|
|
|||
|
public PacketData(PackCMD cmd, object data) : this(cmd)
|
|||
|
{
|
|||
|
this.Data = data;
|
|||
|
}
|
|||
|
|
|||
|
private byte[] _body;
|
|||
|
public byte[] EncData(string key)
|
|||
|
{
|
|||
|
if (_body != null) return _body;
|
|||
|
try
|
|||
|
{
|
|||
|
string aes_data = string.Empty;
|
|||
|
var _json = HttpHelper.ObjectToJson(Data);
|
|||
|
if (_json != null)
|
|||
|
{
|
|||
|
var aes = new AESCryption();
|
|||
|
aes_data = aes.AesEncrypt(_json, key);
|
|||
|
}
|
|||
|
string need = (int)Cmd + " " + aes_data + "\r\n";
|
|||
|
_body = Encoding.UTF8.GetBytes(need);
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
return _body;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|