iText 8.0.5 API
iText.Kernel.Pdf.PdfEncryption Class Reference
Inheritance diagram for iText.Kernel.Pdf.PdfEncryption:
iText.Kernel.Pdf.PdfObjectWrapper< PdfDictionary >

Public Member Functions

  PdfEncryption (byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType, byte[] documentId, PdfVersion version)
  Creates the encryption. More...
 
  PdfEncryption (IX509Certificate[] certs, int[] permissions, int encryptionType, PdfVersion version)
  Creates the certificate encryption. More...
 
  PdfEncryption (PdfDictionary pdfDict, byte[] password, byte[] documentId)
 
  PdfEncryption (PdfDictionary pdfDict, IPrivateKey certificateKey, IX509Certificate certificate)
 
virtual ? long  GetPermissions ()
  Gets the encryption permissions. More...
 
virtual int  GetCryptoMode ()
  Gets encryption algorithm and access permissions. More...
 
virtual bool  IsMetadataEncrypted ()
 
virtual bool  IsEmbeddedFilesOnly ()
 
virtual byte[]  GetDocumentId ()
 
virtual void  SetHashKeyForNextObject (int objNumber, int objGeneration)
 
virtual OutputStreamEncryption  GetEncryptionStream (Stream os)
 
virtual byte[]  EncryptByteArray (byte[] b)
 
virtual byte[]  DecryptByteArray (byte[] b)
 
virtual bool  IsOpenedWithFullPermission ()
 
virtual byte[]  ComputeUserPassword (byte[] ownerPassword)
  Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 algorithm. More...
 
override void  Flush ()
  To manually flush a PdfObject behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference. More...
 
- Public Member Functions inherited from iText.Kernel.Pdf.PdfObjectWrapper< PdfDictionary >
virtual T  GetPdfObject ()
 
virtual iText.Kernel.Pdf.PdfObjectWrapper< T >  MakeIndirect (PdfDocument document, PdfIndirectReference reference)
  Marks object behind wrapper to be saved as indirect. More...
 
virtual iText.Kernel.Pdf.PdfObjectWrapper< T >  MakeIndirect (PdfDocument document)
  Marks object behind wrapper to be saved as indirect. More...
 
virtual iText.Kernel.Pdf.PdfObjectWrapper< T >  SetModified ()
 
virtual bool  IsFlushed ()
 

Static Public Member Functions

static byte[]  GenerateNewDocumentId ()
 
static PdfObject  CreateInfoId (byte[] id, bool modified)
  Creates a PdfLiteral that contains an array of two id entries. More...
 
static PdfObject  CreateInfoId (byte[] firstId, byte[] secondId)
  Creates a PdfLiteral that contains an array of two id entries. More...
 
static PdfObject  CreateInfoId (byte[] firstId, byte[] secondId, bool preserveEncryption)
  Creates a PdfLiteral that contains an array of two id entries. More...
 

Package Functions

override bool  IsWrappedObjectMustBeIndirect ()
  Defines if the object behind this wrapper must be an indirect object in the resultant document. More...
 
- Package Functions inherited from iText.Kernel.Pdf.PdfObjectWrapper< PdfDictionary >
  PdfObjectWrapper (T pdfObject)
 
virtual void  SetPdfObject (T pdfObject)
 
virtual void  SetForbidRelease ()
 
virtual void  UnsetForbidRelease ()
 
virtual void  EnsureUnderlyingObjectHasIndirectReference ()
 

Additional Inherited Members

- Static Package Functions inherited from iText.Kernel.Pdf.PdfObjectWrapper< PdfDictionary >
static void  MarkObjectAsIndirect (PdfObject pdfObject)
 
static void  EnsureObjectIsAddedToDocument (PdfObject @object)
  Some wrappers use object's indirect reference to obtain the PdfDocument to which the object belongs to. More...
 

Constructor & Destructor Documentation

◆ PdfEncryption() [1/2]

iText.Kernel.Pdf.PdfEncryption.PdfEncryption ( byte[]  userPassword,
byte[]  ownerPassword,
int  permissions,
int  encryptionType,
byte[]  documentId,
PdfVersion  version 
)
inline

Creates the encryption.

Parameters
userPassword the user password. Can be null or of zero length, which is equal to omitting the user password
ownerPassword the owner password. If it's null or empty, iText will generate a random string to be used as the owner password
permissions the user permissions The open permissions for the document can be EncryptionConstants.ALLOW_PRINTING , EncryptionConstants.ALLOW_MODIFY_CONTENTS , EncryptionConstants.ALLOW_COPY , EncryptionConstants.ALLOW_MODIFY_ANNOTATIONS , EncryptionConstants.ALLOW_FILL_IN , EncryptionConstants.ALLOW_SCREENREADERS , EncryptionConstants.ALLOW_ASSEMBLY and EncryptionConstants.ALLOW_DEGRADED_PRINTING. The permissions can be combined by ORing them
encryptionType the type of encryption. It can be one of EncryptionConstants.STANDARD_ENCRYPTION_40 , EncryptionConstants.STANDARD_ENCRYPTION_128 , EncryptionConstants.ENCRYPTION_AES_128 or EncryptionConstants.ENCRYPTION_AES_256. Optionally EncryptionConstants.DO_NOT_ENCRYPT_METADATA can be ORed to output the metadata in cleartext. EncryptionConstants.EMBEDDED_FILES_ONLY can be ORed as well. Please be aware that the passed encryption types may override permissions: EncryptionConstants.STANDARD_ENCRYPTION_40 implicitly sets EncryptionConstants.DO_NOT_ENCRYPT_METADATA and EncryptionConstants.EMBEDDED_FILES_ONLY as false; EncryptionConstants.STANDARD_ENCRYPTION_128 implicitly sets EncryptionConstants.EMBEDDED_FILES_ONLY as false;
documentId document id which will be used for encryption
version the PdfVersion of the target document for encryption

◆ PdfEncryption() [2/2]

iText.Kernel.Pdf.PdfEncryption.PdfEncryption ( IX509Certificate[]  certs,
int[]  permissions,
int  encryptionType,
PdfVersion  version 
)
inline

Creates the certificate encryption.

Creates the certificate encryption.

An array of one or more public certificates must be provided together with an array of the same size for the permissions for each certificate.

Parameters
certs the public certificates to be used for the encryption
permissions the user permissions for each of the certificates The open permissions for the document can be EncryptionConstants.ALLOW_PRINTING , EncryptionConstants.ALLOW_MODIFY_CONTENTS , EncryptionConstants.ALLOW_COPY , EncryptionConstants.ALLOW_MODIFY_ANNOTATIONS , EncryptionConstants.ALLOW_FILL_IN , EncryptionConstants.ALLOW_SCREENREADERS , EncryptionConstants.ALLOW_ASSEMBLY and EncryptionConstants.ALLOW_DEGRADED_PRINTING. The permissions can be combined by ORing them
encryptionType the type of encryption. It can be one of EncryptionConstants.STANDARD_ENCRYPTION_40 , EncryptionConstants.STANDARD_ENCRYPTION_128 , EncryptionConstants.ENCRYPTION_AES_128 or EncryptionConstants.ENCRYPTION_AES_256. Optionally EncryptionConstants.DO_NOT_ENCRYPT_METADATA can be ORed to output the metadata in cleartext. EncryptionConstants.EMBEDDED_FILES_ONLY can be ORed as well. Please be aware that the passed encryption types may override permissions: EncryptionConstants.STANDARD_ENCRYPTION_40 implicitly sets EncryptionConstants.DO_NOT_ENCRYPT_METADATA and EncryptionConstants.EMBEDDED_FILES_ONLY as false; EncryptionConstants.STANDARD_ENCRYPTION_128 implicitly sets EncryptionConstants.EMBEDDED_FILES_ONLY as false;
version the PdfVersion of the target document for encryption

Member Function Documentation

◆ ComputeUserPassword()

virtual byte [] iText.Kernel.Pdf.PdfEncryption.ComputeUserPassword ( byte[]  ownerPassword )
inlinevirtual

Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 algorithm.

Parameters
ownerPassword owner password of the encrypted document.
Returns
user password, or null if not a standard encryption handler was used.

◆ CreateInfoId() [1/3]

static PdfObject iText.Kernel.Pdf.PdfEncryption.CreateInfoId ( byte[]  firstId,
byte[]  secondId 
)
inlinestatic

Creates a PdfLiteral that contains an array of two id entries.

Creates a PdfLiteral that contains an array of two id entries. These entries are both hexadecimal strings containing 16 hex characters. The first entry is the original id, the second entry should be different from the first one if the document has changed.

Parameters
firstId the first id
secondId the second id
Returns
PdfObject containing the two entries.

◆ CreateInfoId() [2/3]

static PdfObject iText.Kernel.Pdf.PdfEncryption.CreateInfoId ( byte[]  firstId,
byte[]  secondId,
bool  preserveEncryption 
)
inlinestatic

Creates a PdfLiteral that contains an array of two id entries.

Creates a PdfLiteral that contains an array of two id entries. These entries are both hexadecimal strings containing up to 16 hex characters. The first entry is the original id, the second entry should be different from the first one if the document has changed.

Parameters
firstId the first id
secondId the second id
preserveEncryption the encryption preserve
Returns
PdfObject containing the two entries.

◆ CreateInfoId() [3/3]

static PdfObject iText.Kernel.Pdf.PdfEncryption.CreateInfoId ( byte[]  id,
bool  modified 
)
inlinestatic

Creates a PdfLiteral that contains an array of two id entries.

Creates a PdfLiteral that contains an array of two id entries. These entries are both hexadecimal strings containing 16 hex characters. The first entry is the original id, the second entry should be different from the first one if the document has changed.

Parameters
id the first id
modified whether the document has been changed or not
Returns
PdfObject containing the two entries.

◆ Flush()

override void iText.Kernel.Pdf.PdfEncryption.Flush ( )
inlinevirtual

To manually flush a PdfObject behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference.

To manually flush a PdfObject behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference. Basically this means that before flushing you need to explicitly call PdfObjectWrapper.MakeIndirect(PdfDocument). For example: wrapperInstance.makeIndirect(document).flush(); Note that not every wrapper require this, only those that have such warning in documentation.

Reimplemented from iText.Kernel.Pdf.PdfObjectWrapper< PdfDictionary >.

◆ GetCryptoMode()

virtual int iText.Kernel.Pdf.PdfEncryption.GetCryptoMode ( )
inlinevirtual

Gets encryption algorithm and access permissions.

Returns
the crypto mode value
See also
EncryptionConstants

◆ GetDocumentId()

virtual byte [] iText.Kernel.Pdf.PdfEncryption.GetDocumentId ( )
inlinevirtual
Returns
document id which was used for encryption. Could be null, if encryption doesn't rely on document id.

◆ GetPermissions()

virtual ? long iText.Kernel.Pdf.PdfEncryption.GetPermissions ( )
inlinevirtual

Gets the encryption permissions.

Gets the encryption permissions. It can be used directly in WriterProperties.SetStandardEncryption(byte[], byte[], int, int). See ISO 32000-1, Table 22 for more details.

Returns
the encryption permissions, an unsigned 32-bit quantity.

◆ IsWrappedObjectMustBeIndirect()

override bool iText.Kernel.Pdf.PdfEncryption.IsWrappedObjectMustBeIndirect ( )
inlinepackagevirtual

Defines if the object behind this wrapper must be an indirect object in the resultant document.

Defines if the object behind this wrapper must be an indirect object in the resultant document.

If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.

Return value of this method shouldn't depend on any logic, it should return always true or false.

Returns
true if in the resultant document the object behind the wrapper must be indirect, otherwise false.

Implements iText.Kernel.Pdf.PdfObjectWrapper< PdfDictionary >.