Ejemplo n.º 1
0
 /// <summary>
 /// Saves the data of the instance in the given <paramref name="stream"/>.
 /// </summary>
 /// <param name="stream">The <see cref="Stream"/> to save data in.</param>
 public void Save(Stream stream)
 {
     // Compose the decrypted file contents in a temporary stream.
     using (MemoryStream decStream = new MemoryStream())
     {
         // Write out the file data into a temporary stream.
         Offsets = new List <int>();
         using (MemoryStream dataStream = new MemoryStream())
         {
             SaveData(dataStream);
             Pbdf.WriteHeader(decStream, BlockSize, Offsets, (int)dataStream.Position);
             dataStream.Position = 0;
             dataStream.CopyTo(decStream);
         }
         // Encrypt the data into the provided stream.
         decStream.Position = 0;
         Pbdf.Encrypt(decStream, stream, Key, BlockSize);
     }
 }