Skip to content

Instantly share code, notes, and snippets.

@AeroStun
Created July 11, 2019 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AeroStun/743c15a59579c13fd6cb0f0c13c9a70d to your computer and use it in GitHub Desktop.
Save AeroStun/743c15a59579c13fd6cb0f0c13c9a70d to your computer and use it in GitHub Desktop.
// ScreenTask.React
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
public class React
{
public static object[] De(byte[] array, int first)
{
byte[] array2 = new byte[first];
byte[] array3 = new byte[array.Length - first];
Array.Copy(array, array2, array.Length - (array.Length - first));
Array.Copy(array, first, array3, 0, array.Length - first);
return new byte[2][]
{
array2,
array3
};
}
public static string De(string text, string password, bool decompressText)
{
byte[] bytes = Encoding.UTF8.GetBytes(password);
byte[] passwordBytes = SHA256.Create().ComputeHash(bytes);
byte[] bytesToBeDecrypted = Convert.FromBase64String(text);
byte[] array = AES_Decrypt(bytesToBeDecrypted, passwordBytes);
int saltLength = GetSaltLength();
byte[] array2 = new byte[array.Length - saltLength];
for (int i = 0; i < array2.Length; i++)
{
array2[i] = array[i + saltLength];
}
return Encoding.UTF8.GetString(array2);
}
public static byte[] AES_Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)
{
byte[] result = null;
byte[] salt = new byte[8]
{
1,
2,
3,
4,
5,
6,
7,
8
};
using (MemoryStream memoryStream = new MemoryStream())
{
using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
{
rijndaelManaged.KeySize = 256;
rijndaelManaged.BlockSize = 128;
Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passwordBytes, salt, 1000);
rijndaelManaged.Key = rfc2898DeriveBytes.GetBytes(rijndaelManaged.KeySize / 8);
rijndaelManaged.IV = rfc2898DeriveBytes.GetBytes(rijndaelManaged.BlockSize / 8);
rijndaelManaged.Mode = CipherMode.CBC;
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelManaged.CreateDecryptor(), CryptoStreamMode.Write))
{
cryptoStream.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
cryptoStream.Close();
}
result = memoryStream.ToArray();
}
}
return result;
}
public static byte[] GetRandomBytes()
{
int saltLength = GetSaltLength();
byte[] array = new byte[saltLength];
RandomNumberGenerator.Create().GetBytes(array);
return array;
}
public static int GetSaltLength()
{
return 8;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment