private static bool EncrypteFile(PrivatePublicKeyHelper ppk, string key, string keyType) { Console.Clear(); ConsoleEx.TitleBar(0, "Encrypte File", ConsoleColor.Yellow, ConsoleColor.DarkBlue); Console.Clear(); ConsoleEx.TitleBar(0, string.Format("Encrypte File With {0}", keyType), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteLine(0, 2, "Filename:", ConsoleColor.Cyan); var fileName = Console.ReadLine(); ConsoleEx.WriteLine(0, 4, "", ConsoleColor.Cyan); if (!File.Exists(fileName)) { ConsoleEx.WriteLine(0, 3, "Cannot find the file", ConsoleColor.Red); return(false); } var dataFile = File.ReadAllBytes(fileName); var dataEncrypted = ppk.EncryptBuffer(dataFile, key); var tmpFile = fileName + ENCRYPTED_EXTENSION; if (File.Exists(tmpFile)) { File.Delete(tmpFile); } File.WriteAllBytes(tmpFile, dataEncrypted); Console.WriteLine(string.Format("Encyrpted file is located at {0}", tmpFile), ConsoleColor.Cyan); Pause(); return(true); }
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(); }