Example #1
0
        private static bool encryptionData(ref byte[] rawData, string path, int count, int maxCount, EncryptionArgv encArgv, Headers headerObj)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            byte[] headerData = new byte[] { };

            Console.Write("  + Enc(" + count.ToString() + "/" + maxCount.ToString() + "): " + path + " - ");
            sw.Reset();
            sw.Start();

            if (encArgv.IsOriginalFile)
            {
                headerData = headerObj.MakeHeader(path, ref rawData);
            }

            encArgv.InitializeAesSalt();
            bool success = Chipher.Aes.EncryptFile(path, encArgv, headerData, ref rawData);


            sw.Stop();
            if (success)
            {
                Console.WriteLine("(Done: " + sw.ElapsedMilliseconds.ToString() + "ms)");
            }
            return(success);
        }
Example #2
0
        private static long startEncryption(EncryptionArgv encArgv)
        {
            bool isFolderCompress = encArgv.EncFileInfo.IsCompressedZipFile;

            encArgv.EncFileInfo.IsCompressedZipFile = false;
            Headers headerObj = new Headers(encArgv);

            byte[] rawData = null;

            var swAll = new System.Diagnostics.Stopwatch();

            encArgv.InitializeAesSalt();

            Console.WriteLine("\r\n[*] Starting file encryption...");
            int count    = 0;
            int maxCount = encArgv.PathList.Length;

            if (isFolderCompress)
            {
                maxCount += +encArgv.FolderPathList.Length;
            }
            swAll.Reset();
            swAll.Start();
            // File List
            foreach (string pathData in encArgv.PathList)
            {
                if (cancelFlag)
                {
                    Console.WriteLine("\r\n\r\n[!] Encryption is canceled.");
                    break;
                }
                count++;

                try
                {
                    rawData = readAllFile(pathData);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\r\n    - Failed: " + ex.Message);
                    continue;
                }

                encryptionData(ref rawData, pathData, count, maxCount, encArgv, headerObj);
            }

            encArgv.EncFileInfo.IsCompressedZipFile = isFolderCompress;
            // FolderList
            if (!cancelFlag & encArgv.EncFileInfo.IsCompressedZipFile)
            {
                headerObj = new Headers(encArgv);
                foreach (string pathData in encArgv.FolderPathList)
                {
                    try
                    {
                        if (cancelFlag)
                        {
                            Console.WriteLine("\r\n\r\n[!] Encryption is canceled.");
                            break;
                        }

                        count++;
                        string path = pathData;
                        Console.Write("  + Compressing Folder: " + path + " - ");
                        string zipPath = "";
                        rawData = makeAndReadZipData(pathData, out zipPath, encArgv);
                        Console.WriteLine("(Done.)");
                        path = zipPath;

                        bool success = encryptionData(ref rawData, path, count, maxCount, encArgv, headerObj);
                        if (encArgv.NeedDeleteFile & success)
                        {
                            try
                            {
                                if (encArgv.NeedFillDeleteFile)
                                {
                                    Console.Write("    - Info: Filling up 0x00 data in folder... - ");
                                    foreach (string filePath in Directory.EnumerateFiles(pathData, "*", SearchOption.AllDirectories))
                                    {
                                        IOObject.DeleteFileEx(filePath, encArgv.NeedFillDeleteFile, false);
                                    }
                                    Console.WriteLine("(Done.)");
                                }
                                IOObject.DeleteDirectory(pathData);
                            } catch (Exception ex)
                            {
                                Console.WriteLine("\r\n    - Failed: " + ex.Message + "\r\n");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("\r\n    - Failed: " + ex.Message);
                    }
                }
            }
            swAll.Stop();
            return(swAll.ElapsedMilliseconds);
        }