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(); } }
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; } }
/// <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); }
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; }
/// <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); }
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); } } }
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); } } }
/// <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); }
internal virtual void SetDecryption(int decryptInfoNum, int decryptInfoGen, PdfEncryption decryption) { this.decryptInfoNum = decryptInfoNum; this.decryptInfoGen = decryptInfoGen; this.decryption = decryption; }