PdfEncryption { public byte[] computeUserPassword(byte[] ownerPassword) { byte[] userPad = null; if (publicKeyHandler.getRecipientsSize() == 0 && STANDARD_ENCRYPTION_40 <= revision && revision <= AES_128) { userPad = computeOwnerKey(ownerKey, padPassword(ownerPassword)); for (int i = 0; i < userPad.length; i++) { boolean match = true; for (int j = 0; j < userPad.length - i; j++) { if (userPad[i + j] != pad[j]) { match = false; break; } } if (!match) continue; byte[] userPassword = new byte[i]; System.arraycopy(userPad, 0, userPassword, 0, i); return userPassword; } } return userPad; } PdfEncryption();  PdfEncryption(PdfEncryption enc); void setCryptoMode(int mode, int kl); int getCryptoMode(); boolean isMetadataEncrypted(); long getPermissions(); boolean isEmbeddedFilesOnly(); void setupAllKeys(byte userPassword[], byte ownerPassword[],
			int permissions); boolean readKey(PdfDictionary enc, byte[] password); static byte[] createDocumentId(); void setupByUserPassword(byte[] documentID, byte userPassword[],
			byte ownerKey[], long permissions); void setupByOwnerPassword(byte[] documentID, byte ownerPassword[],
			byte userKey[], byte ownerKey[], long permissions); void setKey(byte[] key); void setupByEncryptionKey(byte[] key, int keylength); void setHashKey(int number, int generation); static PdfObject createInfoId(byte id[], boolean modified); PdfDictionary getEncryptionDictionary(); PdfObject getFileID(boolean modified); OutputStreamEncryption getEncryptionStream(OutputStream os); int calculateStreamSize(int n); byte[] encryptByteArray(byte[] b); StandardDecryption getDecryptor(); byte[] decryptByteArray(byte[] b); void addRecipient(Certificate cert, int permission); byte[] computeUserPassword(byte[] ownerPassword); static final int STANDARD_ENCRYPTION_40; static final int STANDARD_ENCRYPTION_128; static final int AES_128; static final int AES_256; }
@Test public void computeUserPasswordAES256() throws Exception { String encryptedPdf = SOURCE_FOLDER + "cmp_AES256Encrypted.pdf"; PdfReader reader = new PdfReader(encryptedPdf, ownerPassword); byte[] password = reader.computeUserPassword(); reader.close(); assertNull(password); }