예제 #1
0
        public void CreateRecycleBin(Stream stream, Group recycleBin)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // Encrypt protected fields
            var crypto = CryptoSerializer
                         .Create(_headers);

            _xmlWriter.Encrypt(crypto);

            // Headers
            var bw = new BinaryWriter(stream);

            new HeadersWriter(bw)
            .Write(_headers, _version);

            // Main XML
            using (var encrypted = Encrypt(stream,
                                           _headers, _masterKey))
            {
                _xmlWriter.CreateRecycleBin(encrypted,
                                            recycleBin);
            }
        }
예제 #2
0
        public void LoadExisting(Stream existing, byte[] masterKey)
        {
            if (existing == null)
            {
                throw new ArgumentNullException("existing");
            }
            if (masterKey == null)
            {
                throw new ArgumentNullException("masterKey");
            }

            var reader = new BinaryReader(existing);

            if (!FileFormat.Sign(reader))
            {
                throw new FormatException(
                          "Invalid format detected");
            }

            _version = FileFormat
                       .ReadVersion(reader);

            _masterKey = masterKey;
            _headers   = FileFormat
                         .ReadHeaders(existing);

            _xmlWriter = new XmlWriter();

            using (var decrypt = FileFormat.Decrypt(
                       existing, _headers, masterKey))
            {
                _xmlWriter.Load(decrypt);

                var crypto = CryptoSerializer
                             .Create(_headers);
                _xmlWriter.Decrypt(crypto);
            }
        }