public static void SaveSettings() { try { if (File.Exists(_settingsFile)) { var settings = new Dictionary <string, string> { { "Memory Encryption", Globals.MemoryEncryption.ToString() }, { "Anonymous Rename", Globals.AnonymousRename.ToString() }, { "Overwrite Files", Globals.OverwriteFiles.ToString() }, { "Argon2 Memory Size", Invariant.ToString(Globals.MemorySize) }, { "Argon2 Iterations", Invariant.ToString(Globals.Iterations) }, }; using var streamWriter = new StreamWriter(_settingsFile); foreach (var keyValuePair in settings) { streamWriter.WriteLine($"{keyValuePair.Key}: {keyValuePair.Value}"); } } else { File.Create(_settingsFile).Close(); SaveSettings(); } } catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex)) { Logging.LogException(ex.ToString(), Logging.Severity.High); DisplayMessage.Error(ex.GetType().Name, "Unable to save settings."); } }
public static void PerformBenchmark(int delayPerFile) { Console.WriteLine(); RunBenchmark(delayPerFile); KryptorSettings.SaveSettings(); // Deallocate RAM for Argon2 GC.Collect(); Console.WriteLine(); Console.WriteLine($"Argon2 will use a memory size of {Invariant.ToString(Globals.MemorySize / Constants.Mebibyte)} MiB. This value can be changed in the settings."); }
private static void EncryptionCompleted(bool encryption) { GC.Collect(); string outputMessage; if (encryption) { outputMessage = "encrypted"; } else { outputMessage = "decrypted"; } Console.WriteLine(); Console.WriteLine($"Successfully {outputMessage}: {Invariant.ToString(Globals.SuccessfulCount)}/{Invariant.ToString(Globals.TotalCount)}"); }
public static void WriteHeaders(FileStream ciphertext, byte[] salt) { NullChecks.FileHeaders(ciphertext, salt); byte[] memorySizeFlag = Encoding.UTF8.GetBytes(Constants.MemorySizeFlag + Invariant.ToString(Globals.MemorySize)); byte[] iterationsFlag = Encoding.UTF8.GetBytes(Constants.IterationsFlag + Invariant.ToString(Globals.Iterations)); byte[] endFlag = Encoding.UTF8.GetBytes(Constants.EndFlag); ciphertext.Write(memorySizeFlag, 0, memorySizeFlag.Length); ciphertext.Write(iterationsFlag, 0, iterationsFlag.Length); ciphertext.Write(endFlag, 0, endFlag.Length); ciphertext.Write(salt, 0, salt.Length); }