iText 7 7.1.9 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 (X509Certificate[] certs, int[] permissions, int encryptionType, PdfVersion version)
  Creates the certificate encryption. More...
 
  PdfEncryption (PdfDictionary pdfDict, byte[] password, byte[] documentId)
 
  PdfEncryption (PdfDictionary pdfDict, ICipherParameters certificateKey, X509Certificate 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...
 

Detailed Description

<author>Paulo Soares</author> <author>Kazuya Ujihara</author>

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.

Creates the encryption. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. 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.

Parameters
userPassword the user password. Can be null or empty
ownerPassword the owner password. Can be null or empty
permissions the user permissions
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
version the PdfVersion of the target document for encryption

◆ PdfEncryption() [2/2]

iText.Kernel.Pdf.PdfEncryption.PdfEncryption ( X509Certificate[]  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. 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.

Parameters
certs the public certificates to be used for the encryption
permissions the user permissions for each of the certificates
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

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/2]

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/2]

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<T>.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.

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.