コード例 #1
0
        public PdfWriter(Stream os, WriterProperties properties)
            : base(FileUtil.WrapWithBufferedOutputStream(os))
        {
            // For internal usage only
            //forewarned is forearmed
            this.properties = properties;
            EncryptionProperties encryptProps = properties.encryptionProperties;

            if (properties.IsStandardEncryptionUsed())
            {
                crypto = new PdfEncryption(encryptProps.userPassword, encryptProps.ownerPassword, encryptProps.standardEncryptPermissions
                                           , encryptProps.encryptionAlgorithm, PdfEncryption.GenerateNewDocumentId());
            }
            else
            {
                if (properties.IsPublicKeyEncryptionUsed())
                {
                    crypto = new PdfEncryption(encryptProps.publicCertificates, encryptProps.publicKeyEncryptPermissions, encryptProps
                                               .encryptionAlgorithm);
                }
            }
            if (properties.debugMode)
            {
                SetDebugMode();
            }
        }
コード例 #2
0
ファイル: PdfString.cs プロジェクト: zymemail/itext7-dotnet
 protected internal virtual void GenerateValue()
 {
     System.Diagnostics.Debug.Assert(content != null, "No byte[] content to generate value");
     value = PdfEncodings.ConvertToString(DecodeContent(), null);
     if (decryption != null)
     {
         decryption = null;
         content    = null;
     }
 }
コード例 #3
0
 /// <summary>
 /// Encrypt content of
 /// <c>value</c>
 /// and set as content.
 /// <c>generateContent()</c>
 /// won't be called.
 /// </summary>
 /// <param name="encrypt">@see PdfEncryption</param>
 /// <returns>true if value was encrypted, otherwise false.</returns>
 protected internal virtual bool Encrypt(PdfEncryption encrypt)
 {
     if (encrypt != null && !encrypt.IsEmbeddedFilesOnly())
     {
         byte[] b = encrypt.EncryptByteArray(GetValueBytes());
         content = EncodeBytes(b);
         return(true);
     }
     return(false);
 }
コード例 #4
0
ファイル: PdfString.cs プロジェクト: zymemail/itext7-dotnet
 protected internal override void CopyContent(PdfObject from, PdfDocument document)
 {
     base.CopyContent(from, document);
     iText.Kernel.Pdf.PdfString @string = (iText.Kernel.Pdf.PdfString)from;
     value          = @string.value;
     hexWriting     = @string.hexWriting;
     decryption     = @string.decryption;
     decryptInfoNum = @string.decryptInfoNum;
     decryptInfoGen = @string.decryptInfoGen;
     encoding       = @string.encoding;
 }
コード例 #5
0
 /// <summary>
 /// Decrypt content of an encrypted
 /// <c>PdfString</c>
 /// .
 /// </summary>
 protected internal virtual iText.Kernel.Pdf.PdfString Decrypt(PdfEncryption decrypt)
 {
     if (decrypt != null)
     {
         System.Diagnostics.Debug.Assert(content != null, "No byte content to decrypt value");
         byte[] decodedContent = PdfTokenizer.DecodeStringContent(content, hexWriting);
         content = null;
         decrypt.SetHashKeyForNextObject(decryptInfoNum, decryptInfoGen);
         value = PdfEncodings.ConvertToString(decrypt.DecryptByteArray(decodedContent), null);
     }
     return(this);
 }
コード例 #6
0
ファイル: PdfWriter.cs プロジェクト: zymemail/itext7-dotnet
        protected internal virtual void InitCryptoIfSpecified(PdfVersion version)
        {
            EncryptionProperties encryptProps = properties.encryptionProperties;

            if (properties.IsStandardEncryptionUsed())
            {
                crypto = new PdfEncryption(encryptProps.userPassword, encryptProps.ownerPassword, encryptProps.standardEncryptPermissions
                                           , encryptProps.encryptionAlgorithm, PdfEncryption.GenerateNewDocumentId(), version);
            }
            else
            {
                if (properties.IsPublicKeyEncryptionUsed())
                {
                    crypto = new PdfEncryption(encryptProps.publicCertificates, encryptProps.publicKeyEncryptPermissions, encryptProps
                                               .encryptionAlgorithm, version);
                }
            }
        }
コード例 #7
0
        protected internal virtual void InitCryptoIfSpecified(PdfVersion version)
        {
            EncryptionProperties encryptProps = properties.encryptionProperties;

            if (properties.IsStandardEncryptionUsed())
            {
                crypto = new PdfEncryption(encryptProps.userPassword, encryptProps.ownerPassword, encryptProps.standardEncryptPermissions
                                           , encryptProps.encryptionAlgorithm, ByteUtils.GetIsoBytes(this.document.GetOriginalDocumentId().GetValue
                                                                                                         ()), version);
            }
            else
            {
                if (properties.IsPublicKeyEncryptionUsed())
                {
                    crypto = new PdfEncryption(encryptProps.publicCertificates, encryptProps.publicKeyEncryptPermissions, encryptProps
                                               .encryptionAlgorithm, version);
                }
            }
        }
コード例 #8
0
ファイル: PdfString.cs プロジェクト: zymemail/itext7-dotnet
 /// <summary>
 /// Encrypt content of
 /// <c>value</c>
 /// and set as content.
 /// <c>generateContent()</c>
 /// won't be called.
 /// </summary>
 /// <param name="encrypt">@see PdfEncryption</param>
 /// <returns>true if value was encrypted, otherwise false.</returns>
 protected internal virtual bool Encrypt(PdfEncryption encrypt)
 {
     if (CheckState(PdfObject.UNENCRYPTED))
     {
         return(false);
     }
     if (encrypt != decryption)
     {
         if (decryption != null)
         {
             GenerateValue();
         }
         if (encrypt != null && !encrypt.IsEmbeddedFilesOnly())
         {
             byte[] b = encrypt.EncryptByteArray(GetValueBytes());
             content = EncodeBytes(b);
             return(true);
         }
     }
     return(false);
 }
コード例 #9
0
ファイル: PdfString.cs プロジェクト: zymemail/itext7-dotnet
 internal virtual void SetDecryption(int decryptInfoNum, int decryptInfoGen, PdfEncryption decryption)
 {
     this.decryptInfoNum = decryptInfoNum;
     this.decryptInfoGen = decryptInfoGen;
     this.decryption     = decryption;
 }