// Archiwizuje wskazany po ścieżce plik public void ArchiveFile(string path) { if (!IsOpen) { throw new Exception("Archiwum nieotwarte"); } if (!ArchiveKey.IsDerived) { throw new Exception("Klucz niewyprowadzony"); } if (!File.Exists(path)) { throw new Exception("Plik pod wskazaną lokalizacją nie istnieje"); } FileData file = FileData.Create(path); string plaintextName = file.NameStr; if (!FileNameUnique(plaintextName)) { throw new FileNamingException(plaintextName); } if (IsCompressed) { FileCompressor.CompressFile(file); } FileEncryptor.EncryptFile(file, ArchiveKey); SQLiteCommand command = new SQLiteCommand(Connection); command.CommandText = "INSERT INTO FileData(name_l, name, content_l, content, iv) VALUES" + "(" + "'" + Convert.ToString(file.NameLength) + "', " + "@Name, " + "'" + Convert.ToString(file.ContentLength) + "', " + "@Content, " + "@IV" + ")"; command.Parameters.Add(new SQLiteParameter("Name", file.Name)); command.Parameters.Add(new SQLiteParameter("Content", file.Content)); command.Parameters.Add(new SQLiteParameter("IV", file.IV)); command.ExecuteNonQuery(); command.CommandText = "SELECT last_insert_rowid();"; long lastRowId = (long)command.ExecuteScalar(); int fileId = (int)lastRowId; // Przechowanie pary id_pliku-nazwa_pliku IdFileNamePairs.Add(fileId, plaintextName); }
private static bool Encrypt() { #if DEBUG { return(true); } #else return(FileEncryptor.EncryptFile(GetSettingsFileName, _key)); #endif }