/// <summary> /// Initializes a new instance of the <see cref="PbdfFile"/> class from the given <paramref name="stream"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> to load data from.</param> public PbdfFile(Stream stream, object parameter = null) { Parameter = parameter; // Retrieve encryption secrets. Key = Pbdf.RetrieveKey(stream); stream.Position = 0; BlockSize = Pbdf.RetrieveBlockSize(stream, Key); stream.Position = 0; // Decrypt header and data into a temporary stream. byte[] buffer = new byte[stream.Length - (stream.Length / BlockSize * sizeof(uint))]; using (MemoryStream decStream = new MemoryStream(buffer)) { Pbdf.Decrypt(stream, decStream, Key, BlockSize); // Read the header and adjusted offsets. decStream.Position = 0; Offsets = Pbdf.ReadHeader(decStream, BlockSize); int headerSize = (int)decStream.Position; // Create a stream view on the data excluding the header. using (MemoryStream dataStream = new MemoryStream(buffer, headerSize, buffer.Length - headerSize)) LoadData(dataStream); } }