iTextSharp.text.pdf.PdfEncryption.GetEncryptionStream C# (CSharp) Метод

GetEncryptionStream() публичный Метод

public GetEncryptionStream ( Stream os ) : OutputStreamEncryption
os Stream
Результат OutputStreamEncryption
        public OutputStreamEncryption GetEncryptionStream(Stream os)
        {
            return new OutputStreamEncryption(os, key, 0, keySize, revision);
        }

Usage Example

Пример #1
0
        public override void ToPdf(PdfWriter writer, Stream os)
        {
            if (inputStream != null && compressed)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            PdfEncryption crypto = null;

            if (writer != null)
            {
                crypto = writer.Encryption;
            }
            if (crypto != null)
            {
                PdfObject filter = Get(PdfName.FILTER);
                if (filter != null)
                {
                    if (PdfName.CRYPT.Equals(filter))
                    {
                        crypto = null;
                    }
                    else if (filter.IsArray())
                    {
                        PdfArray a = ((PdfArray)filter);
                        if (a.Size > 0 && PdfName.CRYPT.Equals(a[0]))
                        {
                            crypto = null;
                        }
                    }
                }
            }
            PdfObject nn = Get(PdfName.LENGTH);

            if (crypto != null && nn != null && nn.IsNumber())
            {
                int sz = ((PdfNumber)nn).IntValue;
                Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
                SuperToPdf(writer, os);
                Put(PdfName.LENGTH, nn);
            }
            else
            {
                SuperToPdf(writer, os);
            }
            os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            if (inputStream != null)
            {
                rawLength = 0;
                ZDeflaterOutputStream  def = null;
                OutputStreamCounter    osc = new OutputStreamCounter(os);
                OutputStreamEncryption ose = null;
                Stream fout = osc;
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    fout = ose = crypto.GetEncryptionStream(fout);
                }
                if (compressed)
                {
                    fout = def = new ZDeflaterOutputStream(fout, compressionLevel);
                }

                byte[] buf = new byte[4192];
                while (true)
                {
                    int n = inputStream.Read(buf, 0, buf.Length);
                    if (n <= 0)
                    {
                        break;
                    }
                    fout.Write(buf, 0, n);
                    rawLength += n;
                }
                if (def != null)
                {
                    def.Finish();
                }
                if (ose != null)
                {
                    ose.Finish();
                }
                inputStreamLength = (int)osc.Counter;
            }
            else
            {
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    byte[] b;
                    if (streamBytes != null)
                    {
                        b = crypto.EncryptByteArray(streamBytes.ToArray());
                    }
                    else
                    {
                        b = crypto.EncryptByteArray(bytes);
                    }
                    os.Write(b, 0, b.Length);
                }
                else
                {
                    if (streamBytes != null)
                    {
                        streamBytes.WriteTo(os);
                    }
                    else
                    {
                        os.Write(bytes, 0, bytes.Length);
                    }
                }
            }
            os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }
All Usage Examples Of iTextSharp.text.pdf.PdfEncryption::GetEncryptionStream