/// <summary>
        /// Overrides the default implementation to encrypt the data, then write it to the underlying stream
        /// </summary>
        /// <param name="pfo"></param>
        protected override void WriteIndirectStreamData(IIndirectObject pfo)
        {
            if (this.TraceLog.ShouldLog(TraceLevel.Debug))
            {
                this.TraceLog.Begin(TraceLevel.Debug, "Secure Writer", "Encrypting stream for object '" + pfo.Number + " " + pfo.Generation + "'");
            }
            using (var mon = this._monitor.Record(PerformanceMonitorType.Encrypting_Streams, pfo.ToString()))
            {
                byte[]        unencrypted = pfo.Stream.GetStreamData();
                IStreamFilter enc         = CreateEncryptionFilter(pfo.Number, pfo.Generation);
                byte[]        encrypted   = enc.FilterStream(unencrypted);

                if (this.TraceLog.ShouldLog(TraceLevel.Debug))
                {
                    this.TraceLog.Add(TraceLevel.Debug, "Encryption", "Encrypted stream from original " + unencrypted.Length + "bytes, now writing " + encrypted.Length + " encypted data bytes");
                }

                this.BaseStream.Write(Constants.StartStream);
                this.BaseStream.Write(encrypted);
                this.BaseStream.Write(Constants.EndStream);
            }
            if (this.TraceLog.ShouldLog(TraceLevel.Debug))
            {
                this.TraceLog.End(TraceLevel.Debug, "Secure Writer", "Encrypting stream for object '" + pfo.Number + " " + pfo.Generation + "'");
            }
            else if (this.TraceLog.ShouldLog(TraceLevel.Verbose))
            {
                this.TraceLog.Add(TraceLevel.Verbose, "Encryption", "Encrypted the stream data for " + pfo.ToString());
            }
        }
예제 #2
0
        private void CompressFontFileData(byte[] orig)
        {
            IStreamFilter filter = PDFStreamFilters.FlateDecode;

            this._filtereddata = filter.FilterStream(orig);
            this._filterName   = filter.FilterName;
        }
예제 #3
0
        private byte[] ApplyFilters(IStreamFilter[] filters, byte[] input)
        {
            byte[] output = null;
            try
            {
                for (int i = 0; i < filters.Length; i++)
                {
                    IStreamFilter filter = this.Filters[i];
                    output = filter.FilterStream(input);
                    input  = output;
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format(CommonErrors.CouldNotApplyStreamFilters, this.IndirectObject.ToString(), ex.Message);
                throw new PDFStreamException(msg, ex);
            }

            return(output);
        }
예제 #4
0
        /// <summary>
        /// Overrides the default implementation to encrypt the data, then write it to the underlying stream
        /// </summary>
        /// <param name="pfo"></param>
        protected override void WriteIndirectStreamData(IIndirectObject pfo)
        {
            if (this.TraceLog.ShouldLog(TraceLevel.Debug))
            {
                this.TraceLog.Begin(TraceLevel.Debug, "Secure Writer", "Encrypting stream for object '" + pfo.Number + " " + pfo.Generation + "'");
            }

            byte[]        unencrypted = pfo.Stream.GetStreamData();
            IStreamFilter enc         = CreateEncryptionFilter(pfo.Number, pfo.Generation);

            byte[] encrypted = enc.FilterStream(unencrypted);
            if (this.TraceLog.ShouldLog(TraceLevel.Debug))
            {
                this.TraceLog.Add(TraceLevel.Debug, "Encryption", "Encrypted stream data, now writing");
            }
            this.BaseStream.Write(Constants.StartStream);
            this.BaseStream.Write(encrypted);
            this.BaseStream.Write(Constants.EndStream);

            if (this.TraceLog.ShouldLog(TraceLevel.Debug))
            {
                this.TraceLog.End(TraceLevel.Debug, "Secure Writer", "Encrypting stream for object '" + pfo.Number + " " + pfo.Generation + "'");
            }
        }