Security.cs
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace HslCommunication
{
internal class HslSecurity
{
#region Encryption and decryption
/*******************************************************************************
*
* 用于加密解密的方法,为了性能考虑,使用了相对简单的加密解密方式,紧紧对当前的程序集开放
*
* Method for encryption and decryption, for performance reasons, using relatively simple encryption and decryption
*
*******************************************************************************/
/// <summary>
/// 加密方法,只对当前的程序集开放
/// </summary>
/// <param name="enBytes">等待加密的数据</param>
/// <returns>加密后的字节数据</returns>
internal static byte[] ByteEncrypt(byte[] enBytes)
{
if (enBytes == null) return null;
byte[] result = new byte[enBytes.Length];
for (int i = 0; i < enBytes.Length; i++)
{
result[i] = (byte)(enBytes[i] ^ 0xB5);
}
return result;
}
/// <summary>
/// 解密方法,只对当前的程序集开放
/// </summary>
/// <param name="deBytes">等待解密的数据</param>
/// <returns>解密后的字节数据</returns>
internal static byte[] ByteDecrypt(byte[] deBytes)
{
return ByteEncrypt(deBytes);
}
#endregion
}
}