Esempio n. 1
0
        private static void Crypt(IReadOnlyList <string> args)
        {
            var sourceFolder    = args[0];
            var destinationPath = args[1];
            var keysFile        = args[2];

            if (!Directory.Exists(destinationPath))
            {
                Extensions.PrintText("You need to enter the destination path to the folder in the second argument", ConsoleColor.Red);
                return;
            }

            var cryptor = new Cryptor(sourceFolder, destinationPath, keysFile);

            cryptor.Crypt();
        }
Esempio n. 2
0
        private static void Decrypt(IReadOnlyList <string> args)
        {
            var archive         = args[1];
            var destinationPath = args[2];
            var keysFile        = args[3];

            Extensions.PrintText("Decrypt: \n", ConsoleColor.Green);

            if (!File.Exists(archive))
            {
                Extensions.PrintText("You need to enter the archive in the first argument", ConsoleColor.Red);
                return;
            }

            var cryptor = new Cryptor(archive, destinationPath, keysFile);

            Cryptor.Decrypt(cryptor, archive, destinationPath, keysFile);
        }
Esempio n. 3
0
        public static bool Decrypt(Cryptor cryptor, string archivePath, string destinationPath, string keysFile)
        {
            ZipFile.ExtractToDirectory(archivePath, destinationPath);

            cryptor.GetAllFilesForDecrypt(destinationPath);

            using var keysFileStream = File.Open(keysFile, FileMode.Open);
            using var memoryStream   = new MemoryStream();

            keysFileStream.CopyTo(memoryStream);

            var keysAndIv = Encoding.UTF8.GetString(memoryStream.ToArray()).Split("\n");

            keysAndIv = keysAndIv.Take(keysAndIv.Count() - 1).ToArray();

            var keyAndIvSplit = new List <string[]>();

            foreach (var kiv in keysAndIv)
            {
                keyAndIvSplit.Add(kiv.Split("#"));
            }

            for (var index = 0; index < cryptor._allPathsForDecrypt.Count; index++)
            {
                var filePath = cryptor._allPathsForDecrypt[index];

                var keyIv = keyAndIvSplit[index];
                var key   = keyIv[0];
                var iv    = keyIv[1];

                Console.Write(CryptFile.DecryptFile(filePath, key, Encoding.Unicode.GetBytes(iv)));
            }


            return(true);
        }