AesHelper.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5. namespace Showlicense
  6. {
  7. internal static class AesHelper
  8. {
  9. /// <summary>
  10. /// "Vinno.vCloud.CurrentLicense" two MD5
  11. /// </summary>
  12. private const string Key = "2A4A2B05EFD02D5BDEBB55711213BBBD";
  13. /// <summary>
  14. /// Gets Decrypt text
  15. /// </summary>
  16. /// <param name="inputText"></param>
  17. /// <returns></returns>
  18. internal static string Decrypt(string inputText)
  19. {
  20. return AesDecrypt(inputText, Key);
  21. }
  22. /// <summary>
  23. /// AES algorithm Decrypt string
  24. /// </summary>
  25. /// <param name="cipherText"></param>
  26. /// <param name="keyString">AES Key</param>
  27. /// <returns></returns>
  28. private static string AesDecrypt(string cipherText, string keyString)
  29. {
  30. var fullCipher = Convert.FromBase64String(cipherText);
  31. byte[] iv = new byte[16];
  32. var cipher = new byte[fullCipher.Length - iv.Length];
  33. Buffer.BlockCopy(fullCipher, 0, iv, 0, iv.Length);
  34. Buffer.BlockCopy(fullCipher, iv.Length, cipher, 0, fullCipher.Length - iv.Length);
  35. var key = Encoding.UTF8.GetBytes(keyString);
  36. using (var aesAlg = Aes.Create())
  37. {
  38. using (var decryptor = aesAlg.CreateDecryptor(key, iv))
  39. {
  40. string result;
  41. using (var msDecrypt = new MemoryStream(cipher))
  42. {
  43. using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
  44. {
  45. using (var srDecrypt = new StreamReader(csDecrypt))
  46. {
  47. result = srDecrypt.ReadToEnd();
  48. }
  49. }
  50. }
  51. return result;
  52. }
  53. }
  54. }
  55. }
  56. }