public void SetUp() { _console = new UnitTestConsole(); _console.Interface.BufferWidth = 100; _console.Interface.WindowWidth = 100; _settings = StaticUtilities.GenerateKeyPair(); }
public void Handle(IConsoleAdapter console, IErrorAdapter error, Settings keyPair) { var data = BufferUtils.GetFileContents(EncryptedFile); string key; if (!SkipPassword) { var pword = SetupSystem.RequestPassword(); //the key is decrypted with CipherTools decryption, using the AES algorithm key = CipherTools.Decrypt<AesManaged>(keyPair.PrivateKey, pword, "salty"); } else { key = keyPair.PrivateKey; } byte[] dataOut; if (NoDecompression) //data is decrypted with the private key dataOut = PrivateKeyDecryption.Decrypt(key, data); else { //data is decrypted with the private key data = PrivateKeyDecryption.Decrypt(key, data); //data is decompressed dataOut = Compression.Decompress(data); } //data is written to file BufferUtils.WriteToFile(DecryptedFile, dataOut); console.WrapLine("EncryptedFile = {0}".Yellow(), EncryptedFile.Cyan()); console.WrapLine("DecryptedFile = {0}".Yellow(), DecryptedFile.Cyan()); }
public void Handle(IConsoleAdapter console, IErrorAdapter error, Settings settings) { console.WrapLine("Exporting public key file".Green()); console.WrapLine("The file will be in XML format".Green()); string location = null; //user is prompted to specify a location until select a valid one - either option one or option two while (location == null) { console.WrapLine("Please Select a valid location to export the file to:".Yellow()); console.WrapLine(" (1) Desktop".White()); console.WrapLine(" (2) Documents".White()); console.WrapLine("Enter number:".Yellow()); var option = Console.ReadLine(); location = GetLocation(option); if (location == null) { console.WrapLine("Invalid Location, Please choose again".Red()); } } XmlHandler.CreateFile(settings, location); }
//serialises a new XML file public static void CreateFile(Settings settings, String path) { using (var writer = new StreamWriter(path)) { var ser = new XmlSerializer(typeof(Settings)); ser.Serialize(writer, settings); } }
//reads an XML file into the settings class and returns true for successful reading and false if not public static bool ReadFile(Settings settings) { var path = SetupSystem.CreateFilePath(); if (!File.Exists(path)) return false; using (var reader = new StreamReader(path)) { var ser = new XmlSerializer(typeof(Settings)); var loadedSettings = ser.Deserialize(reader) as Settings; settings.CopyFrom(loadedSettings); return true; } }
public void Handle(IConsoleAdapter console, IErrorAdapter error, Settings settings) { console.WriteLine("On average, encryption with compression is taking {0} to complete, press enter to continue..", ProcessingTime.GetAverageTime()); console.ReadLine(); ProcessingTime.StartTimer(); //the file is stored in a byte array called data var data = BufferUtils.GetFileContents(OriginalFile); //if they have selected the option of external key then the variable key will contain the //external key, otherwise the public key is taken from the settings object var key = OtherKey ? GetExternalKey() : settings.PublicKey; if (NoCompression) { //if the user selected the option no compression then the file is encrypted without compressing first data = PublicKeyEncryption.Encrypt(key, data); console.WrapLine("Encryption complete".Blue()); } else { //if the user didn't specify the option no compression then the file is compressed and then encrypted data = Compression.Compress(data); console.WrapLine("Compression complete".Green()); data = PublicKeyEncryption.Encrypt(key, data); console.WrapLine("Encryption complete".Blue()); } //the byte array is then written to the encrypted file location BufferUtils.WriteToFile(EncryptedFile, data); console.WrapLine("OriginalFile = {0}".Yellow(), OriginalFile.Cyan()); console.WrapLine("EncryptedFile = {0}".Yellow(), EncryptedFile.Cyan()); ProcessingTime.StopTimer(); }
public void CopyFrom(Settings loadedSettings) { PublicKey = loadedSettings.PublicKey; PrivateKey = loadedSettings.PrivateKey; }
//uses CipherTools to encrypt the private key using an AES encryption algorithm private static string EncyrptPrivateKey(Settings keyPair, string pword) { return CipherTools.Encrypt<AesManaged>(keyPair.PrivateKey, pword, "salty"); }
public void SetUp() { _data = "test data".ToCharArray().Select(c => (byte)c).ToArray(); _settings = StaticUtilities.GenerateKeyPair(); }
public void SetUp() { _keyPair = SetupSystem.GenerateKeyPair(); }
public void SetUp() { _settings = StaticUtilities.GenerateKeyPair(); _documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/keys.xml"; _desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/keys.xml"; }