Пример #1
0
 /// <summary>
 /// Creates a new backup index
 /// </summary>
 /// <param name="path">
 /// The path to the backup index file to create
 /// </param>
 /// <param name="header">
 /// The backup index header to insert
 /// </param>
 /// <returns>
 /// A new backup index implementation
 /// </returns>
 public static IBackupIndex Create(IO.Path path, Header header)
 {
     // create the backup index file and schema
      Database.Create(path, "SkyFloe.Sqlite.Resources.BackupIndex.sql");
      var index = (BackupIndex)null;
      try
      {
     // connect to the database and add the header row
     index = new BackupIndex(path);
     index.Execute(
        "INSERT INTO Header (" +
        "   Version, " +
        "   CryptoIterations, " +
        "   ArchiveSalt, " +
        "   PasswordHash, " +
        "   PasswordSalt) " +
        "VALUES (@p0, @p1, @p2, @p3, @p4);",
        header.Version = CurrentVersion,
        header.CryptoIterations,
        header.ArchiveSalt,
        header.PasswordHash,
        header.PasswordSalt
     );
     return index;
      }
      catch
      {
     if (index != null)
        index.Dispose();
     try { Database.Delete(path); } catch { }
     throw;
      }
 }
Пример #2
0
 /// <summary>
 /// Creates and connects to a new backup archive
 /// </summary>
 /// <param name="name">
 /// The name of the archive to create
 /// </param>
 /// <param name="password">
 /// The security password for the archive
 /// </param>
 public void CreateArchive(String name, String password)
 {
     // validate parameters
      if (this.Connection == null)
     throw new InvalidOperationException(Strings.ConnectionNotConnected);
      if (this.archive != null)
     throw new InvalidOperationException(Strings.ConnectionAlreadyConnected);
      var store = this.Connection.Store;
      try
      {
     // verify that the archive does not already exist at the store
     if (store.ListArchives().Contains(name, StringComparer.OrdinalIgnoreCase))
        throw new InvalidOperationException(
           String.Format(Strings.EngineArchiveExists, name)
        );
     // create the archive header and encryption parameters
     var random = RandomNumberGenerator.Create();
     var header = new Backup.Header()
     {
        CryptoIterations = DefaultCryptoIterations,
        ArchiveSalt = new Byte[DefaultCryptoSaltLength],
        PasswordSalt = new Byte[DefaultCryptoSaltLength]
     };
     random.GetBytes(header.ArchiveSalt);
     random.GetBytes(header.PasswordSalt);
     using (var hash = CreateHasher(password, header))
        header.PasswordHash = hash.GetBytes(DefaultCryptoHashLength);
     // attach the encryption algorithm and
     // delegate to the store implementation to create the archive
     this.crypto = CreateCrypto(password, header);
     this.archive = store.CreateArchive(name, header);
      }
      catch
      {
     CloseArchive();
     throw;
      }
 }