Security.cs 1.6 KB

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