EncryptUtils.cs 1016 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. using UnityEngine;
  9. public class EncryptUtils
  10. {
  11. private const string encryptKey = "YobnSB4gBcXiqtot";//"gVBFoCxAcvNk4JCr";
  12. //AES加密
  13. public static string AesEncrypt(string value)
  14. {
  15. if (string.IsNullOrEmpty(value)) return string.Empty;
  16. var _keyByte = Encoding.UTF8.GetBytes(encryptKey);
  17. var _valueByte = Encoding.UTF8.GetBytes(value);
  18. using (var aes = new RijndaelManaged())
  19. {
  20. aes.IV = _keyByte;
  21. aes.Key = _keyByte;
  22. aes.Mode = CipherMode.CBC;
  23. aes.Padding = PaddingMode.PKCS7;
  24. var cryptoTransform = aes.CreateEncryptor();
  25. var resultArray = cryptoTransform.TransformFinalBlock(_valueByte.ToArray(), 0, _valueByte.Length);
  26. return Convert.ToBase64String(resultArray, 0, resultArray.Length);
  27. }
  28. }
  29. }