Class PdfEncryption


  • public class PdfEncryption
    extends Object
    Author:
    Paulo Soares (psoares@consiste.pt), Kazuya Ujihara
    • Constructor Detail

      • PdfEncryption

        public PdfEncryption()
    • Method Detail

      • createDocumentId

        public static byte[] createDocumentId()
      • createInfoId

        public static PdfObject createInfoId​(byte[] id)
      • createInfoId

        public static PdfObject createInfoId​(byte[] idPartOne,
                                             byte[] idPartTwo)
      • getFileIdChangingPart

        public static byte[] getFileIdChangingPart​(PdfObject fileId)
        This method returns a changing part of the fileId when can be identified. Returns a complete fileId of the changing part is not found.
        Parameters:
        fileId - PdfObject
        Returns:
        byte array representing the changing part of the document identifier
      • setCryptoMode

        public void setCryptoMode​(int mode,
                                  int kl)
      • getCryptoMode

        public int getCryptoMode()
      • isMetadataEncrypted

        public boolean isMetadataEncrypted()
      • isEmbeddedFilesOnly

        public boolean isEmbeddedFilesOnly()
        Indicates if only the embedded files have to be encrypted.
        Returns:
        if true only the embedded files will be encrypted
        Since:
        2.1.3
      • setupAllKeys

        public void setupAllKeys​(byte[] userPassword,
                                 byte[] ownerPassword,
                                 int permissions)
      • setupByUserPassword

        public void setupByUserPassword​(byte[] documentID,
                                        byte[] userPassword,
                                        byte[] ownerKey,
                                        int permissions)
        Parameters:
        documentID - byte array of document id
        userPassword - byte array of user password
        ownerKey - byte array of owner key
        permissions - permissions
      • setupByOwnerPassword

        public void setupByOwnerPassword​(byte[] documentID,
                                         byte[] ownerPassword,
                                         byte[] userKey,
                                         byte[] ownerKey,
                                         int permissions)
        Parameters:
        documentID - byte array of document id
        ownerPassword - byte array of owner password
        userKey - byte array of user key
        ownerKey - byte array of owner key
        permissions - permissions
      • setupByEncryptionKey

        public void setupByEncryptionKey​(byte[] key,
                                         int keylength)
      • setHashKey

        public void setHashKey​(int number,
                               int generation)
      • getEncryptionDictionary

        public PdfDictionary getEncryptionDictionary()
      • calculateStreamSize

        public int calculateStreamSize​(int n)
      • encryptByteArray

        public byte[] encryptByteArray​(byte[] b)
      • decryptByteArray

        public byte[] decryptByteArray​(byte[] b)
      • addRecipient

        public void addRecipient​(Certificate cert,
                                 int permission)
      • computeUserPassword

        public byte[] computeUserPassword​(byte[] ownerPassword)
      • setupByOwnerPassword

        public void setupByOwnerPassword​(byte[] documentID,
                                         byte[] ownerPassword,
                                         byte[] uValue,
                                         byte[] ueValue,
                                         byte[] oValue,
                                         byte[] oeValue,
                                         int permissions)
                                  throws GeneralSecurityException
        implements step d of Algorithm 2.A: Retrieving the file encryption key from an encrypted document in order to decrypt it (revision 6 and later) - ISO 32000-2 section 7.6.4.3.3
        Throws:
        GeneralSecurityException
      • setupByUserPassword

        public void setupByUserPassword​(byte[] documentID,
                                        byte[] userPassword,
                                        byte[] uValue,
                                        byte[] ueValue,
                                        byte[] oValue,
                                        byte[] oeValue,
                                        int permissions)
                                 throws GeneralSecurityException
        implements step e of Algorithm 2.A: Retrieving the file encryption key from an encrypted document in order to decrypt it (revision 6 and later) - ISO 32000-2 section 7.6.4.3.3
        Throws:
        GeneralSecurityException
      • decryptAndCheckPerms

        public boolean decryptAndCheckPerms​(byte[] permsValue)
                                     throws GeneralSecurityException
        implements step f of Algorithm 2.A: Retrieving the file encryption key from an encrypted document in order to decrypt it (revision 6 and later) - ISO 32000-2 section 7.6.4.3.3
        Throws:
        GeneralSecurityException