EncryptHelper.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Buffers.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace IoTIntegrationPlatform.Common
  9. {
  10. /// <summary>
  11. /// 加解密公共类
  12. /// </summary>
  13. public static class EncryptHelper
  14. {
  15. //private readonly static string key = "DD57F2D5CAA11BDC";
  16. /// <summary>
  17. /// AES64位加密
  18. /// </summary>
  19. /// <param name="content"></param>
  20. /// <returns></returns>
  21. public static string AESEncrypt(string content,string key)
  22. {
  23. string result = string.Empty;
  24. try
  25. {
  26. byte[] bytes = AESHelper.Encrypt(content, key);
  27. result = Convert.ToBase64String(bytes);
  28. }
  29. catch (Exception ex)
  30. {
  31. Logging.Error(ex, ex.Message);
  32. }
  33. return result;
  34. }
  35. /// <summary>
  36. /// AES64位解密
  37. /// </summary>
  38. /// <param name="content"></param>
  39. public static string AESDecryption(string content, string key)
  40. {
  41. string result = string.Empty;
  42. try
  43. {
  44. byte[] bytes = Convert.FromBase64String(content);
  45. result = Encoding.Default.GetString(AESHelper.Decrypt(bytes, key));
  46. }
  47. catch (Exception ex)
  48. {
  49. Logging.Error(ex, ex.Message);
  50. }
  51. return result;
  52. }
  53. }
  54. }