public static void CreateKeyfile(string filePath) { NullChecks.Strings(filePath); const string keyfileExtension = ".key"; // Generate a random name if the path is a directory if (Directory.Exists(filePath)) { string randomFileName = AnonymousRename.GenerateRandomFileName() + keyfileExtension; filePath = Path.Combine(filePath, randomFileName); } if (!File.Exists(filePath)) { // Append .key extension if missing if (!filePath.EndsWith(keyfileExtension, StringComparison.InvariantCulture)) { filePath += keyfileExtension; } Keyfiles.GenerateKeyfile(filePath); } else { Console.WriteLine("Error: A file with this name already exists."); } }
public static string KeyfilePath(string keyfilePath) { try { const string keyfileExtension = ".key"; // Generate a random keyfile if (Directory.Exists(keyfilePath)) { string randomFileName = ObfuscateFileName.GetRandomFileName() + keyfileExtension; keyfilePath = Path.Combine(keyfilePath, randomFileName); } // Append keyfile extension if missing if (!keyfilePath.EndsWith(keyfileExtension, StringComparison.InvariantCulture)) { keyfilePath += keyfileExtension; } Keyfiles.GenerateKeyfile(keyfilePath); return(keyfilePath); } catch (Exception ex) when(ExceptionFilters.FileAccess(ex)) { Logging.LogException(ex.ToString(), Logging.Severity.Error); DisplayMessage.FilePathException(keyfilePath, ex.GetType().Name, "Unable to randomly generate keyfile."); return(null); } }
private static byte[] UseKeyfile(byte[] passwordBytes, string keyfilePath) { try { byte[] keyfileBytes = Keyfiles.ReadKeyfile(keyfilePath); return(passwordBytes == null ? keyfileBytes : CombineKeyfileAndPassword(passwordBytes, keyfileBytes)); } catch (Exception ex) when(ExceptionFilters.FileAccess(ex)) { DisplayMessage.Exception(ex.GetType().Name, "Unable to read keyfile. The keyfile has not been used."); return(passwordBytes); } }
private static byte[] GetKeyfileBytes(byte[] passwordBytes, string keyfilePath) { if (!string.IsNullOrEmpty(keyfilePath)) { byte[] keyfileBytes = Keyfiles.ReadKeyfile(keyfilePath); if (keyfileBytes != null) { MemoryEncryption.DecryptByteArray(ref passwordBytes); // Combine password and keyfile bytes passwordBytes = HashingAlgorithms.Blake2(passwordBytes, keyfileBytes); MemoryEncryption.EncryptByteArray(ref passwordBytes); Utilities.ZeroArray(keyfileBytes); } } return(passwordBytes); }
private static byte[] KeyfileAsPassword(string keyfilePath) { // If only a keyfile was selected, use the keyfile bytes as the password byte[] passwordBytes = Keyfiles.ReadKeyfile(keyfilePath); return(HashPasswordBytes(passwordBytes)); }