Exemplo n.º 1
0
        private static void UnitTests(PrivatePublicKeyHelper ppk, sFs.sFsManager sFsManager)
        {
            Console.Clear();
            var sw = Stopwatch.StartNew();

            var source          = @"C:\@USB_STICK_Data\Img_4950.jpg";
            var sourceExtension = Path.GetExtension(source);

            ppk.PrivateKey = sFsManager["PrivateKey"].GetBufferAsUnicodeString();
            ppk.PublicKey  = sFsManager["PublicKey"].GetBufferAsUnicodeString();
            var dataFile      = File.ReadAllBytes(source);
            var dataEncrypted = ppk.EncryptBuffer(dataFile, ppk.PublicKey);
            var tmpFile       = source + ENCRYPTED_EXTENSION;

            File.WriteAllBytes(tmpFile, dataEncrypted);

            sw.Stop();
            Console.WriteLine("Encryption time: {0}", sw.ElapsedMilliseconds / 1000.0);

            sw = Stopwatch.StartNew();
            var dataFile2 = File.ReadAllBytes(tmpFile);

            dataEncrypted = ppk.DecryptBuffer(dataFile2, ppk.PrivateKey);
            var newFile = tmpFile + sourceExtension;

            File.WriteAllBytes(newFile, dataEncrypted);
            sw.Stop();
            Console.WriteLine("Dencryption time: {0}", sw.ElapsedMilliseconds / 1000.0);
            Pause();
        }
Exemplo n.º 2
0
        private static bool DecrypteFile(PrivatePublicKeyHelper ppk, string key, string keyType)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Decrypte file with {0}", keyType), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.WriteLine(0, 2, "Filename:", ConsoleColor.Cyan);
            var fileName = Console.ReadLine();

            ConsoleEx.Gotoxy(0, 4);

            if (!File.Exists(fileName))
            {
                ConsoleEx.WriteLine(0, 3, "Cannot find the file", ConsoleColor.Red);
                Pause();
                return(false);
            }
            var sourceExtension = Path.GetExtension(fileName.Replace(ENCRYPTED_EXTENSION, ""));
            var dataFile        = File.ReadAllBytes(fileName);
            var dataEncrypted   = ppk.DecryptBuffer(dataFile, key);
            var tmpFile         = fileName + sourceExtension;

            File.WriteAllBytes(tmpFile, dataEncrypted);

            Console.WriteLine(string.Format("Encyrpted file is located at {0}", tmpFile), ConsoleColor.Cyan);
            Pause();
            return(true);
        }