EncryptHelper.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using System.Text;
  5. namespace MySystem
  6. {
  7. public class EncryptHelper
  8. {
  9. public static string Encrypt1(SortedList<string, string> obj, string key)
  10. {
  11. string signstr = function.BuildQueryString(obj) + key;
  12. string sign = function.MD532(signstr).ToUpper();
  13. obj.Add("sign", sign);
  14. return AesEncrypt(Newtonsoft.Json.JsonConvert.SerializeObject(obj), key);
  15. }
  16. public static string AesEncrypt(string str, string key)
  17. {
  18. if (string.IsNullOrEmpty(str)) return null;
  19. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  20. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  21. {
  22. Key = Encoding.UTF8.GetBytes(key),
  23. Mode = System.Security.Cryptography.CipherMode.ECB,
  24. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  25. };
  26. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  27. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  28. return Convert.ToBase64String(resultArray, 0, resultArray.Length);
  29. }
  30. }
  31. }