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(); }
public static void Run(string[] args) { var pw = string.Empty; Console.WriteLine("Nusbio initialization"); Nusbio.ActivateFastMode(); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { pw = AskForPW(nusbio, VolumeName); _sfsManager = new sFs.sFsManager(VolumeName, pw, nusbio: nusbio, clockPin: NusbioGpio.Gpio0, mosiPin: NusbioGpio.Gpio1, misoPin: NusbioGpio.Gpio2, selectPin: NusbioGpio.Gpio3); _sfsManager.Begin(); Cls(nusbio, true); Console.WriteLine(Environment.NewLine + Environment.NewLine); Console.WriteLine("Initializing private public key module"); var ppk = new PrivatePublicKeyHelper(true); //GeneratePrivateKeyPublicKey(pw); var ok = ReloadFileSystem(pw, ppk); if (!ok) { Cls(nusbio, true); if (ConsoleEx.Question(3, string.Format("Cannot access {0} with this password, retry Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }) == 'Y') { Environment.Exit(1); } Cls(nusbio, true); // Re format - re init key var keyInfo = ConsoleEx.Question(4, string.Format("Would you like to initialize {0} Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }); if (keyInfo == 'N') { return; } GeneratePrivateKeyPublicKey(pw); } Cls(nusbio); while (nusbio.Loop()) { if (Console.KeyAvailable) { var kk = Console.ReadKey(true); var k = kk.Key; if (kk.Modifiers == ConsoleModifiers.Control) { if (DigitKeys.Contains(k)) { var a = (int)k - 48; if (a == 0) { a = 10; } a--; ShowFile(a); } } else { if (k == ConsoleKey.A) { AddNewTextFile(pw); } if (k == ConsoleKey.B) { AddNewTextFile(pw, @"C:\Users\fredericaltorres\Dropbox\FTO\MonteChristro.jpg"); } if (k == ConsoleKey.D1) { EncrypteFile(ppk, ppk.PublicKey, "PublicKey"); } if (k == ConsoleKey.D2) { EncrypteFile(ppk, ppk.PrivateKey, "PrivateKey"); } if (k == ConsoleKey.D3) { DecrypteFile(ppk, ppk.PrivateKey, "PrivateKey"); } if (k == ConsoleKey.D4) { ExportKey(ppk.PublicKey, "PublicKey"); } if (k == ConsoleKey.D5) { ExportKey(ppk.PrivateKey, "PrivateKey"); } if (k == ConsoleKey.D6) { GeneratePrivateKeyPublicKey(pw); } if (k == ConsoleKey.U) { UnitTests(ppk, _sfsManager); } if (k == ConsoleKey.Q) { break; } } Cls(nusbio); } } } Console.Clear(); }
public static void Run(string[] args) { SecureString pw; Console.WriteLine("Nusbio initialization"); Nusbio.ActivateFastMode(); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { pw = AskForPW(nusbio, VolumeName); _sfsManager = new sFs.sFsManager(VolumeName, pw, nusbio: nusbio, clockPin: NusbioGpio.Gpio0, mosiPin: NusbioGpio.Gpio1, misoPin: NusbioGpio.Gpio2, selectPin: NusbioGpio.Gpio3); _sFsREPLCommand = new sFs.sFsREPLCommand(_sfsManager); Cls(nusbio, true); Console.WriteLine(Environment.NewLine + Environment.NewLine); var ok = ReloadFileSystem(); if (!ok) { Cls(nusbio, true); if (ConsoleEx.Question(3, string.Format("Cannot access {0} with this password, retry password Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }) == 'Y') { Environment.Exit(1); } Cls(nusbio, true); // Re format - re init key var keyInfo = ConsoleEx.Question(4, string.Format("Would you like to format {0} Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }); if (keyInfo == 'N') { return; } FormatAndInitDisk(); } Cls(nusbio); while (nusbio.Loop()) { Console.Write(string.Format(@"{0}:\>", _sfsManager.VolumeName)); var cmd = Console.ReadLine(); var cmdLC = cmd.ToLowerInvariant(); var tokens = cmdLC.Split(' '); if (tokens.Length > 0) { if (tokens[0] == "exit") { nusbio.ExitLoop(); } if (tokens[0] == "format") { FormatAndInitDisk(); } if (tokens[0] == "cls") { Console.Clear(); } if (tokens[0] == "help") { Console.WriteLine(COMMAND_HELP); } if (tokens[0] == "del") { if (_sfsManager.Delete(cmd.Substring(4))) { if (_sfsManager.UpdateFileSystem()) { Console.WriteLine(SFS_COMMAND_MESSAGE_FILE_DELETED); } else { Console.WriteLine(SFS_COMMAND_ERR_SAVING_FAT); } } else { Console.WriteLine(SFS_COMMAND_ERR_CANNOT_FIND_FILE); } } if (tokens[0] == "compact") { if (_sfsManager.Compact()) { Console.WriteLine(SFS_COMMAND_MESSAGE_COMPACTAGE_DONE); } else { Console.WriteLine(SFS_COMMAND_ERR_COMPACTAGE_FAILED); } } if (tokens[0] == "type") { Console.WriteLine(_sFsREPLCommand.TypeCommand(cmd.Substring(5))); } if (tokens[0] == "open") { Console.WriteLine(_sFsREPLCommand.OpenCommand(cmd.Substring(5))); } if (tokens[0] == "dir") { Console.WriteLine(_sFsREPLCommand.DirCommand()); } if (tokens[0] == "dirall") { Console.WriteLine(_sFsREPLCommand.DirCommand(true)); } if (tokens[0] == "copy") { Console.WriteLine(_sFsREPLCommand.CopyFileCommand(cmd.Substring(5))); } } } } Console.Clear(); }
public sFsREPLCommand(sFsManager sFsManager) { _sFsManager = sFsManager; }