master
lch 8 months ago committed by CZ
commit cf055766d8

@ -1014,8 +1014,8 @@ namespace BatCharging.Service
if (CMD4 != null) if (CMD4 != null)
{ {
byte type = 0; byte type = 0;
uint startAddress = 0; uint startAddress = 1;
byte[] setData = null; byte[] setData = new byte[4];
//(CMD=3)后台服务器下发充电桩字符型参数 //(CMD=3)后台服务器下发充电桩字符型参数
CmnChargerParam._CHR00TCPCLIENT.Send3(type, startAddress, setData); CmnChargerParam._CHR00TCPCLIENT.Send3(type, startAddress, setData);
@ -1035,7 +1035,7 @@ namespace BatCharging.Service
byte type = 0; byte type = 0;
uint startAddress = 0; uint startAddress = 0;
byte num = 0; byte num = 0;
byte[] setData = null; byte[] setData = new byte[4];
//(CMD=5)后台服务器下发充电桩控制命令 //(CMD=5)后台服务器下发充电桩控制命令
CmnChargerParam._CHR00TCPCLIENT.Send5(type, startAddress, num, setData); CmnChargerParam._CHR00TCPCLIENT.Send5(type, startAddress, num, setData);
@ -1053,7 +1053,7 @@ namespace BatCharging.Service
if (CMD8 != null) if (CMD8 != null)
{ {
CMD7 CMD = new CMD7(); CMD7 CMD = new CMD7();
CMD.value13 = "12345678901234567890123456789012";
//(CMD=1)后台服务器下发充电桩整形工作参数 //(CMD=1)后台服务器下发充电桩整形工作参数
CmnChargerParam._CHR00TCPCLIENT.Send7(CMD); CmnChargerParam._CHR00TCPCLIENT.Send7(CMD);

@ -323,7 +323,7 @@ namespace BatCharging.Service
CMD3.value2 = 0; CMD3.value2 = 0;
CMD3.value3 = type; CMD3.value3 = type;
CMD3.value4 = startAddress; CMD3.value4 = startAddress;
CMD3.value5 = pubCommonClass.cmd3StartAddress[startAddress]; CMD3.value5 = PubCommonClass.cmd3StartAddress[startAddress];
CMD3.value6 = setData; CMD3.value6 = setData;
byte[] bytes = new ChargerSendCMD().SendRCMD3(out APDUModel, CMD3); byte[] bytes = new ChargerSendCMD().SendRCMD3(out APDUModel, CMD3);

@ -134,6 +134,41 @@ namespace BatCharging.Service
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes; return returnBytes;
} }
/// <summary>
/// 获取32进制字符串的字节数组
/// </summary>
/// <param name="hexString">hexString 16进制字符串</param>
/// <returns>字节数组</returns>
public static byte[] ToByteByHexStr32(string hexString)
{
// 使用UTF8编码将字符串转换为字节数组
byte[] byteArray = Encoding.UTF8.GetBytes(hexString);
// 输出转换后的字节数组
foreach (var b in byteArray)
{
Console.Write("{0:X2} ", b);
}
// 如果需要确保数组长度为32字节可以添加逻辑来处理长度不足的情况
if (byteArray.Length < 32)
{
List<byte> lstByte = byteArray.ToList();
// 长度不足,可以添加填充或者抛出异常
for (int i = byteArray.Length; i < 32; i++)
{
lstByte.Add(0);
}
byteArray = lstByte.ToArray();
}
else if (byteArray.Length > 32)
{
// 长度超过32字节可以截断或者抛出异常
Console.WriteLine("字符串转换后的字节数组长度超过32字节将截断到32字节。");
Array.Copy(byteArray, 0, new byte[32], 0, 32); // 截断数组到32字节
}
return byteArray;
}
/// <summary> /// <summary>
/// 获取16进制字符串的字节数组 /// 获取16进制字符串的字节数组

@ -52,7 +52,7 @@ namespace BatCharging.Service
{ {
int checksum = 0; int checksum = 0;
for (int i = 8; i < data.Count(); i++)//这里没校验域所以不减一 for (int i = 6; i < data.Count(); i++)//这里没校验域所以不减一
{ {
checksum += data[i]; checksum += data[i];
} }

@ -17,7 +17,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -74,7 +74,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -128,7 +128,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -182,7 +182,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -224,7 +224,7 @@ namespace BatCharging.Service
lstContent.AddRange(BitConverter.GetBytes(CMD.value10)); lstContent.AddRange(BitConverter.GetBytes(CMD.value10));
lstContent.AddRange(BitConverter.GetBytes(CMD.value11)); lstContent.AddRange(BitConverter.GetBytes(CMD.value11));
lstContent.AddRange(BitConverter.GetBytes(CMD.value12)); lstContent.AddRange(BitConverter.GetBytes(CMD.value12));
lstContent.AddRange(ByteUtils.ToByteByHexStr(CMD.value13)); lstContent.AddRange(ByteUtils.ToByteByHexStr32(CMD.value13));
lstContent.AddRange(BitConverter.GetBytes(CMD.value14)); lstContent.AddRange(BitConverter.GetBytes(CMD.value14));
lstContent.AddRange(BitConverter.GetBytes(CMD.value15)); lstContent.AddRange(BitConverter.GetBytes(CMD.value15));
lstContent.AddRange(BitConverter.GetBytes(CMD.value16)); lstContent.AddRange(BitConverter.GetBytes(CMD.value16));
@ -240,7 +240,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -293,7 +293,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -340,7 +340,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -386,7 +386,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -444,7 +444,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -491,7 +491,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -536,7 +536,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -581,7 +581,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -631,7 +631,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -684,7 +684,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -741,7 +741,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -790,7 +790,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -846,7 +846,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -897,7 +897,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -943,7 +943,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -990,7 +990,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1039,7 +1039,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1083,7 +1083,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1127,7 +1127,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1171,7 +1171,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1215,7 +1215,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1260,7 +1260,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1304,7 +1304,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1353,7 +1353,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1396,7 +1396,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1508,7 +1508,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1632,7 +1632,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1678,7 +1678,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1738,7 +1738,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;
@ -1788,7 +1788,7 @@ namespace BatCharging.Service
APDUModel model = new APDUModel(); APDUModel model = new APDUModel();
model.OriginDomain1 = 0xAA; model.OriginDomain1 = 0xAA;
model.OriginDomain1 = 0xF5; model.OriginDomain2 = 0xF5;
model.infoDomain = 0x02; model.infoDomain = 0x02;
model.SerialNumberDomain = 0xff; model.SerialNumberDomain = 0xff;
model.CMD = 1; model.CMD = 1;

@ -8,7 +8,7 @@
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public Dictionary<uint, ushort> cmd3StartAddress = new Dictionary<uint, ushort>(); public static Dictionary<uint, ushort> cmd3StartAddress = new Dictionary<uint, ushort>();
//public Dictionary<> //public Dictionary<>

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Module.Socket.Tool
{
/// <summary>
/// AES加密
/// </summary>
public class AesEncryption
{
private static readonly byte[] Key = Encoding.UTF8.GetBytes("YourSecretKeyHere12345678"); // 必须是32字节256位
private static readonly byte[] Iv = Encoding.UTF8.GetBytes("YourInitializationVectorHere"); // 必须是16字节128位
public static byte[] EncryptStringToBytes(string plainText)
{
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException(nameof(plainText));
if (Key == null || Key.Length != 32)
throw new ArgumentNullException(nameof(Key));
if (Iv == null || Iv.Length != 16)
throw new ArgumentNullException(nameof(Iv));
byte[] encrypted;
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = Iv;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
return encrypted;
}
public static string DecryptBytesToString(byte[] cipherText)
{
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException(nameof(cipherText));
if (Key == null || Key.Length != 32)
throw new ArgumentNullException(nameof(Key));
if (Iv == null || Iv.Length != 16)
throw new ArgumentNullException(nameof(Iv));
string plaintext = null;
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = Iv;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
plaintext = srDecrypt.ReadToEnd();
}
}
return plaintext;
}
}
}

@ -42,6 +42,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AesEncryption.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TcpClientChargerTool.cs" /> <Compile Include="TcpClientChargerTool.cs" />
<Compile Include="ReceivedEventArgs.cs" /> <Compile Include="ReceivedEventArgs.cs" />

@ -392,7 +392,7 @@ namespace Module.Socket.Tool
bool bResult = false; bool bResult = false;
int checksum = 0; int checksum = 0;
for (int i = 8; i < data.Count() - 1; i++)//这里有校验域所以减一 for (int i = 6; i < data.Count() - 1; i++)//这里有校验域所以减一
{ {
checksum += data[i]; checksum += data[i];
} }
@ -438,6 +438,19 @@ namespace Module.Socket.Tool
//校验域是否正确 //校验域是否正确
if (checksumDomainReceive(newBytes)) if (checksumDomainReceive(newBytes))
{
var info = newBytes[4];
if ((info & (1 << 1)) != 0)//AES加密
{
List<byte> byteList = newBytes.ToList();
byteList.Remove(8);
byteList.Remove(8);//移除前面两个长度
newBytes= byteList.ToArray();
lstResult.Add(newBytes);
}
else //不加密
{
lstResult.Add(newBytes); lstResult.Add(newBytes);
} }
} }
@ -446,6 +459,8 @@ namespace Module.Socket.Tool
} }
} }
} }
}
}
{ {

File diff suppressed because it is too large Load Diff

@ -1,3 +1,4 @@
using CommonClass;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -14,6 +15,8 @@ namespace Monitor.ChargeTest
[STAThread] [STAThread]
static void Main() static void Main()
{ {
new PubCommonClass().SetCmd3StartAddress();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmChargeResult()); Application.Run(new FrmChargeResult());

Loading…
Cancel
Save