Beispiel #1
0
        private static void showArgvInfo(EncryptionArgv encArgv)
        {
            if (encArgv.IsEncryption)
            {
                Console.WriteLine("\r\n[*] Encryption setting informations:");
            }
            else
            {
                Console.WriteLine("\r\n[*] Decryption setting informations:");
            }

            string[] info = getArgvStringInfo(encArgv);

            Console.WriteLine("  + Chipher Mode : " + info[0]);
            Console.WriteLine("  + Original File: " + info[1]);
            Console.WriteLine("  + All Files    : " + info[2]);
            Console.WriteLine("  + Force Write  : " + info[3]);
            Console.WriteLine("  + Compress     : " + info[4]);
            Console.WriteLine("  + Output Path  : " + info[5]);
            Console.WriteLine("  + File Lists   : " + info[6] + " file(s)");
            Console.WriteLine("  + Folder Lists : " + info[7] + " folder(s)");
            Console.WriteLine("  + Password Hash: " + info[8]);
            Console.WriteLine("  + AES Mode     : " + info[9]);
            Console.WriteLine("  + AES Padding  : " + info[10]);
            Console.WriteLine("  + AES Key Size : " + info[11] + " bits");
            Console.WriteLine("  + AES BlockSize: " + info[12] + " bits");
        }
Beispiel #2
0
        private static long startDecryption(EncryptionArgv encArgv)
        {
            var sw    = new System.Diagnostics.Stopwatch();
            var swAll = new System.Diagnostics.Stopwatch();

            Console.WriteLine("\r\n[*] Starting file decryption...");
            int count = 0;

            swAll.Reset();
            swAll.Start();
            foreach (string path in encArgv.PathList)
            {
                if (cancelFlag)
                {
                    Console.WriteLine("[!] Decryption is canceled.");
                    break;
                }

                count++;
                bool success = false;
                Console.Write("  + Dec(" + count.ToString() + "/" + encArgv.PathList.Length.ToString() + "): " + path + " - ");
                sw.Reset();
                sw.Start();
                success = Chipher.Aes.DecryptFile(path, encArgv);
                sw.Stop();
                if (success)
                {
                    Console.WriteLine("(Done: " + sw.ElapsedMilliseconds.ToString() + "ms)");
                }
            }

            swAll.Stop();
            return(swAll.ElapsedMilliseconds);
        }
Beispiel #3
0
        private static string[] getArgvStringInfo(EncryptionArgv encArgv)
        {
            List <string> info = new List <string>()
            {
            };

            info.Add("AES Mode");
            info.Add(encArgv.IsOriginalFile.ToString());
            info.Add(encArgv.IsAllFileSelected.ToString());
            info.Add(encArgv.ForceWrite.ToString());
            info.Add(encArgv.intSetCompressLevel.ToString());
            if (encArgv.OutPath == "")
            {
                info.Add("Any directory...");
            }
            else
            {
                info.Add(encArgv.OutPath);
            }
            info.Add(encArgv.PathList.Length.ToString());
            info.Add(encArgv.FolderPathList.Length.ToString());
            info.Add(Chipher.Hash.GetSHA256HashString(encArgv.PrivatePassword));
            info.Add(encArgv.AesInfo.Mode.ToString());
            info.Add(encArgv.AesInfo.Padding.ToString());
            info.Add(encArgv.AesInfo.KeySize.ToString());
            info.Add(encArgv.AesInfo.BlockSize.ToString());

            return(info.ToArray());
        }
Beispiel #4
0
        public Headers(EncryptionArgv encArgvData)
        {
            // Build chipher information header
            encArgv = encArgvData;
            int[] tmpHeader = new int[] { };
            tmpHeader = new int[] {
                1, (int)encArgv.AesInfo.Mode, encArgv.AesInfo.BlockSize - 1, encArgv.AesInfo.KeySize - 1,
                (int)encArgv.AesInfo.Padding, Convert.ToInt32(encArgv.EncFileInfo.IsCompressedZipFile), 0, 0, 0, 0,
            };

            foreach (int data in tmpHeader)
            {
                headerData.Add(Convert.ToByte(data));
            }
        }
Beispiel #5
0
 private static byte[] makeAndReadZipData(string folderPath, out string zipPath, EncryptionArgv encArgv)
 {
     zipPath = folderPath + ".zip";
     if (File.Exists(zipPath))
     {
         zipPath = IOObject.RenameFolder(zipPath);
     }
     using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(zipPath, Encoding.UTF8))
     {
         zip.CompressionLevel = encArgv.CompressLevel;
         zip.AddDirectory(folderPath, "");
         zip.Comment = Path.GetFileName(folderPath);
         zip.Save();
     }
     return(readAllFile(zipPath));
 }
Beispiel #6
0
        private static void Main(string[] args)
        {
            // Exit task
            myHandlerDele = new HandlerRoutine(exitTaskFunc);
            SetConsoleCtrlHandler(myHandlerDele, true);

            Console.Title = "FFCrypt Core " + version;
            Console.WriteLine("\r\n[*] [FFCrypt Core " + version + "]");
            EncryptionArgv encArgv = new EncryptionArgv();
            long           times   = 0;

            try
            {
                Console.WriteLine("[*] Analysing arguments...\r\n");
                encArgv.SetEncryptionArgvValue(args);
                showArgvInfo(encArgv);

                if (encArgv.ShowHelp)
                {
                    showHelpInfo();
                }
                else if (encArgv.IsEncryption)
                {
                    Console.Title = Console.Title + " - Encrypting...";
                    times         = startEncryption(encArgv);
                }
                else
                {
                    Console.Title = Console.Title + " - Decrypting...";
                    times         = startDecryption(encArgv);
                }
                GC.Collect();
            }
            catch (NoFilePathException)
            {
                Console.WriteLine("\r\n[-] Please select the file(s).");
                showHelpInfo();
            }
            catch (NoPasswordException)
            {
                Console.WriteLine("\r\n[-] Please set the password.");
                showHelpInfo();
            }
            catch (CreateDirectoryError)
            {
                Console.WriteLine("\r\n[-] Could not create directory: '" + encArgv.OutPath + "' ");
                showHelpInfo();
            }
            if (encArgv.IsEncryption)
            {
                Console.WriteLine("\r\n[*] Completed encryption. (" + times + "ms)");
            }
            else
            {
                Console.WriteLine("\r\n[*] Completed decryption. (" + times + "ms)");
            }
            taskExited = true;

            Console.Title = "FFCrypt Core " + version;
            if (encArgv.WaitForEnterKey)
            {
                Console.WriteLine("[*] Press Enter to exit this program...");
                Console.ReadLine();
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
0
 public static EncryptionArgv ReadHeaderAndMakeEncryptionArgv(string path, EncryptionArgv encArgv)
 {
     return(encArgv);
 }
Beispiel #10
0
        public bool MakeEncArgv(ref byte[] rawData, ref EncryptionArgv encArgv)
        {
            // Get Header size and Data size
            EncryptionFileInfo efi = new EncryptionFileInfo();

            byte[] headerSizeBytes = new byte[4];
            byte[] dataSizeBytes   = new byte[8];
            Buffer.BlockCopy(rawData, 4, headerSizeBytes, 0, 4);
            Buffer.BlockCopy(rawData, 8, dataSizeBytes, 0, 8);
            int  headerSize = BitConverter.ToInt32(headerSizeBytes, 0);
            long dataSizeL  = BitConverter.ToInt64(dataSizeBytes, 0);

            if (int.MaxValue < dataSizeL)
            {
                return(false);
            }
            int dataSize = (int)dataSizeL;

            byte[] headerRawBytes = new byte[headerSize];
            efi.FileData = new byte[dataSize];
            Buffer.BlockCopy(rawData, 80, headerRawBytes, 0, headerRawBytes.Length);
            Buffer.BlockCopy(rawData, 80 + headerRawBytes.Length, efi.FileData, 0, efi.FileData.Length);

            // Decrypt header data
            byte[] headerBytes = Chipher.Aes.DecryptData(ref headerRawBytes, encArgv.PrivatePassword, MakeDefaultAes());
            headerRawBytes = null;

            // Read binary header data
            efi.IsAesMode = BitConverter.ToBoolean(headerBytes, 0);
            if (efi.IsAesMode)
            {
                encArgv.AesInfo.Mode      = (CipherMode)(int)headerBytes[1];
                encArgv.AesInfo.BlockSize = (int)headerBytes[2] + 1;
                encArgv.AesInfo.KeySize   = (int)headerBytes[3] + 1;
                encArgv.AesInfo.Padding   = (PaddingMode)(int)headerBytes[4];
            }
            efi.IsCompressedZipFile = BitConverter.ToBoolean(headerBytes, 5);

            efi.FileNotContentIndexed = BitConverter.ToBoolean(headerBytes, 10);
            efi.FileOffline           = BitConverter.ToBoolean(headerBytes, 11);
            efi.FileReadOnly          = BitConverter.ToBoolean(headerBytes, 12);
            efi.FileHidden            = BitConverter.ToBoolean(headerBytes, 13);
            efi.FileArchive           = BitConverter.ToBoolean(headerBytes, 14);
            efi.FileSystem            = BitConverter.ToBoolean(headerBytes, 15);
            Buffer.BlockCopy(headerBytes, 16, efi.MD5FileHash, 0, efi.MD5FileHash.Length);

            // Read string header data
            byte[] strHeaderRaw = new byte[headerBytes.Length - 32];
            Buffer.BlockCopy(headerBytes, 32, strHeaderRaw, 0, strHeaderRaw.Length);
            string[] strHeader = Encoding.UTF8.GetString(strHeaderRaw).Split('|');

            efi.FilePath                 = strHeader[0];
            efi.FileName                 = Path.GetFileName(strHeader[0]);
            efi.FileExtension            = Path.GetExtension(strHeader[0]);
            efi.FileNameWithoutExtension = Path.GetFileNameWithoutExtension(strHeader[0]);
            efi.FileDirectory            = Path.GetDirectoryName(strHeader[0]);

            efi.CreationTime   = DateTime.Parse(strHeader[1]);
            efi.LastWriteTime  = DateTime.Parse(strHeader[2]);
            efi.LastAccessTime = DateTime.Parse(strHeader[3]);

            encArgv.SetFileInfo(efi);
            return(true);
        }