Class Encryption


  • public class Encryption
    extends NativeObject

    The parameters to encrypt PDF documents

    PDF document can be encrypted to protect content from unauthorized access. The encryption process applies encryption to all streams (e.g. images) and strings, but not to other items in the PDF document. This means the structure of the PDF document is accessible, but the content of its pages is encrypted.

    The standard security handler allows access permissions and up to two passwords to be specified for a document: A user password (see getUserPassword()) and an owner password (see getOwnerPassword()).

    The following list shows the four possible combinations of passwords and how an application processing such a PDF document behaves:

    • No user password, no owner password (no encryption):

      Everyone can read, i.e. no password required to open the document. Everyone can change security settings.

    • No user password, owner password:

      Everyone can read, i.e. no password required to open the document. Access permissions are restricted (unless the owner password is provided). Owner password required to change security settings.

    • User password, no owner password:

      User password required to read. All access permissions are granted.

    • User password, owner password:

      User or owner password required to read. Access permissions are restricted (unless the owner password is provided). Owner password required to change security settings.

    Since encryption is not allowed by the PDF/A ISO standards, PDF/A documents must not be encrypted.

    • Constructor Summary

      Constructors 
      Constructor Description
      Encryption​(java.lang.String userPassword, java.lang.String ownerPassword, java.util.EnumSet<Permission> permissions)  
    • Constructor Detail

      • Encryption

        public Encryption​(java.lang.String userPassword,
                          java.lang.String ownerPassword,
                          java.util.EnumSet<Permission> permissions)
        Parameters:
        userPassword - Set the user password of the output document (see getUserPassword()). If null or empty, no user password is set.
        ownerPassword - Set the owner password and permissions of the output document (see getOwnerPassword()). If null or empty, no owner password is set.
        permissions - The permissions to be set on the PDF document. If no owner password is set, the permissions must not be restricted, i.e. the permissions must be All.
        Throws:
        java.lang.IllegalArgumentException - if permissions is null
    • Method Detail

      • setPermissions

        public void setPermissions​(java.lang.String ownerPassword,
                                   java.util.EnumSet<Permission> permissions)

        Set the owner password and access permissions.

        Only the given permissions are granted when opening the document. To the owner of the document, all permissions are granted. For this, the document must be opened by specifying the owner password (see getOwnerPassword()).
        Parameters:
        ownerPassword - The owner password to be set on the PDF document (see getOwnerPassword()).
        permissions - The permissions to be set on the PDF document.
        Throws:
        java.lang.IllegalArgumentException - If restricted permissions (i.e. not All) are specified without ownerPassword.
        java.lang.IllegalArgumentException - if ownerPassword is null
        java.lang.IllegalArgumentException - if permissions is null
      • getUserPassword

        public java.lang.String getUserPassword()

        The user password (Getter)

        This password protects the document against unauthorized opening and reading.

        If a PDF document is protected by a user password, it cannot be opened without a password. The user or, if set, owner password must be provided to open and read the document.

        If a document is not protected by a user password, it can be opened by without a password, even if an owner password is set.

        If the password contains characters that are not in the Windows ANSI encoding (Windows Code Page 1252), the output document's compliance level is automatically upgraded to PDF version 1.7. This is because older PDF versions do not support Unicode passwords.

      • setUserPassword

        public void setUserPassword​(java.lang.String value)

        The user password (Setter)

        This password protects the document against unauthorized opening and reading.

        If a PDF document is protected by a user password, it cannot be opened without a password. The user or, if set, owner password must be provided to open and read the document.

        If a document is not protected by a user password, it can be opened by without a password, even if an owner password is set.

        If the password contains characters that are not in the Windows ANSI encoding (Windows Code Page 1252), the output document's compliance level is automatically upgraded to PDF version 1.7. This is because older PDF versions do not support Unicode passwords.

      • getOwnerPassword

        public java.lang.String getOwnerPassword()

        The owner password (Getter)

        This password is sometimes also referred to as the author’s password. This password grants full access to the document. Not only can the document be opened and read, it also allows the document's security settings, access permissions, and passwords to be changed.

        If the password contains characters that are not in the Windows ANSI encoding (Windows Code Page 1252), the output document's compliance level is automatically upgraded to PDF version 1.7. This is because older PDF versions do not support Unicode passwords.

      • getPermissions

        public java.util.EnumSet<Permission> getPermissions()

        The access permissions granted when opening the document (Getter)

        The operations granted in a PDF document are controlled using permission flags. In order to set permission flags, the PDF document must be encrypted and have an owner password.

        The restricted permissions apply whenever the document is opened with a password other than the owner password. The owner password is required to initially set or later change the permission flags.

        When opening an encrypted document, the access permissions for the document can be read using Document.getPermissions(). Note that the permissions might be different from the "Document Restrictions Summary" displayed in Adobe Acrobat.