Advertisement
HenryEx

Unity Decrypt()

Sep 14th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. // UnityExtensions.EncryptionExtensions
  2. public static string Decrypt(this string cipherString)
  3. {
  4.     string result = string.Empty;
  5.     try
  6.     {
  7.         byte[] array = Convert.FromBase64String(cipherString);
  8.         EncryptionExtensions.ValidateInput(cipherString);
  9.         EncryptionExtensions.ValidateInput(EncryptionExtensions.SecurityKey);
  10.         byte b = array[0];
  11.         byte b2 = array[array.Length - 1];
  12.         byte[] array2 = new byte[(int)b2];
  13.         int num = (int)(b2 + 1);
  14.         Buffer.BlockCopy(array, array.Length - num, array2, 0, (int)b2);
  15.         byte[] array3 = new byte[array.Length - 1 - (int)b2 - 1];
  16.         Buffer.BlockCopy(array, 1, array3, 0, array3.Length);
  17.         byte[] bytes = Encoding.UTF8.GetBytes(EncryptionExtensions.SecurityKey);
  18.         byte[] array4 = new byte[bytes.Length + 1];
  19.         Buffer.BlockCopy(bytes, 0, array4, 0, bytes.Length);
  20.         array4[array4.Length - 1] = b;
  21.         SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
  22.         byte[] key = sHA1CryptoServiceProvider.ComputeHash(array4);
  23.         Array.Resize<byte>(ref key, 16);
  24.         sHA1CryptoServiceProvider.Clear();
  25.         TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
  26.         tripleDESCryptoServiceProvider.Key = key;
  27.         tripleDESCryptoServiceProvider.IV = array2;
  28.         tripleDESCryptoServiceProvider.Mode = CipherMode.CFB;
  29.         tripleDESCryptoServiceProvider.Padding = PaddingMode.PKCS7;
  30.         ICryptoTransform cryptoTransform = tripleDESCryptoServiceProvider.CreateDecryptor();
  31.         byte[] bytes2 = cryptoTransform.TransformFinalBlock(array3, 0, array3.Length);
  32.         tripleDESCryptoServiceProvider.Clear();
  33.         result = Encoding.UTF8.GetString(bytes2);
  34.     }
  35.     catch (Exception var_14_11D)
  36.     {
  37.         return "-1";
  38.     }
  39.     return result;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement