Esempio n. 1
0
 public static void DisplayPasswordEntropy(string password, Label lblEntropy)
 {
     if (lblEntropy != null)
     {
         if (!string.IsNullOrEmpty(password))
         {
             int entropy = CalculateEntropy(password);
             if (entropy < 80)
             {
                 lblEntropy.ForeColor = Color.Red;
             }
             else if (entropy >= 80 && entropy < 112)
             {
                 lblEntropy.ForeColor = Color.Orange;
             }
             else if (entropy >= 112)
             {
                 lblEntropy.ForeColor = Color.LimeGreen;
             }
             lblEntropy.Text    = $"{Invariant.ToString(entropy)} bits";
             lblEntropy.Visible = true;
         }
         else
         {
             lblEntropy.Visible = false;
         }
     }
 }
Esempio n. 2
0
        private static void ConvertArgon2Parameters(out byte[] memorySizeBytes, out byte[] iterationsBytes, out byte[] endFlag)
        {
            string memorySize = Constants.MemorySizeFlag + Invariant.ToString(Globals.MemorySize);
            string iterations = Constants.IterationsFlag + Invariant.ToString(Globals.Iterations);
            var    parameters = GetParametersBytes(memorySize, iterations);

            memorySizeBytes = parameters.Item1;
            iterationsBytes = parameters.Item2;
            endFlag         = parameters.Item3;
        }
Esempio n. 3
0
 private void BgwArgon2Benchmark_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     Settings.SaveSettings();
     // Deallocate RAM for Argon2
     GC.Collect();
     Argon2Benchmark.DeleteFirstRunFile();
     this.Hide();
     DisplayMessage.InformationMessageBox($"Argon2 will use a memory size of {Invariant.ToString(Globals.MemorySize / Constants.Mebibyte)} MiB. This value can be changed in the settings.{Environment.NewLine}{Environment.NewLine}For the full benchmark results, please view: {Constants.KryptorDirectory}\\benchmark.txt", "Argon2 Benchmark Results");
     ShowOtherForms();
     this.Close();
 }
Esempio n. 4
0
 public static void SaveSettings()
 {
     try
     {
         if (File.Exists(_settingsFile))
         {
             var settings = new Dictionary <string, string>
             {
                 { "Encryption Algorithm", Invariant.ToString(Globals.EncryptionAlgorithm) },
                 { "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) },
                 { "Show Password", Globals.ShowPasswordByDefault.ToString() },
                 { "Auto Clear Password", Globals.AutoClearPassword.ToString() },
                 { "Auto Clear Clipboard", Invariant.ToString(Globals.ClearClipboardInterval) },
                 { "Exit Clipboard Clear", Globals.ExitClearClipboard.ToString() },
                 { "Shred Files Method", Invariant.ToString(Globals.ShredFilesMethod) },
                 { "Check for Updates", Globals.CheckForUpdates.ToString() },
                 { "Dark Theme", Globals.DarkTheme.ToString() }
             };
             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.ErrorMessageBox(ex.GetType().Name, "Unable to save settings.");
     }
 }
Esempio n. 5
0
 private static void StoreBenchmarkResults(int[] benchmarkTimes, List <int> memorySize, int recommendedMemorySize, int delayPerFile)
 {
     try
     {
         var benchmarkResults = new List <string>();
         for (int i = 0; i < benchmarkTimes.Length; i++)
         {
             benchmarkResults.Add($"{memorySize[i] / Constants.Mebibyte} MiB = {benchmarkTimes[i]} ms");
         }
         benchmarkResults.Add(Environment.NewLine);
         benchmarkResults.Add($"Recommended Memory Size: {Invariant.ToString(recommendedMemorySize / Constants.Mebibyte)} MiB");
         benchmarkResults.Add($"This memory size was chosen because it was <= {delayPerFile} ms. This is the delay per file that it takes for Argon2 to derive an encryption key and MAC key. You can speed up key derivation by lowering the memory size, but this will decrease your security. For more information about Argon2, please read the documentation: https://kryptor.co.uk/Key Derivation.html.");
         string benchmarkFilePath = Path.Combine(Constants.KryptorDirectory, "benchmark.txt");
         File.WriteAllLines(benchmarkFilePath, benchmarkResults);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Low);
         DisplayMessage.ErrorMessageBox(ex.GetType().Name, "Unable to store benchmark results.");
     }
 }
Esempio n. 6
0
 private void BackgroundWorkerCompleted(string outputMessage)
 {
     EnableMenus();
     prgProgress.Visible  = false;
     prgProgress.Value    = 0;
     Globals.ResultsText += Environment.NewLine + $"Successfully {outputMessage}: {Invariant.ToString(Globals.SuccessfulCount)}/{Invariant.ToString(Globals.TotalCount)}";
     using (var results = new frmResults())
     {
         results.ShowDialog();
     }
 }