/** * Returns the security handler specified in the dictionary's Filter entry. * @return a security handler instance * @throws IOException if there is no security handler available which matches the Filter */ public SecurityHandler getSecurityHandler() throws IOException { if (securityHandler == null) { throw new IOException("No security handler for filter " + getFilter()); } return securityHandler; }
setDecryptMetadata(encryption.isEncryptMetaData()); StandardDecryptionMaterial material = (StandardDecryptionMaterial)decryptionMaterial; int dicPermissions = encryption.getPermissions(); int dicRevision = encryption.getRevision(); int dicLength = encryption.getVersion() == 1 ? 5 : encryption.getLength() / 8; boolean encryptMetadata = encryption.isEncryptMetaData(); byte[] userKey = encryption.getUserKey(); byte[] ownerKey = encryption.getOwnerKey(); byte[] ue = null, oe = null; ue = encryption.getUserEncryptionKey(); oe = encryption.getOwnerEncryptionKey(); if (encryption.getVersion() == 4 || encryption.getVersion() == 5) PDCryptFilterDictionary stdCryptFilterDictionary = encryption.getStdCryptFilterDictionary();
@Override public Object visitFromString(COSString obj) throws IOException { if (willEncrypt) { pdDocument.getEncryption().getSecurityHandler().encryptString( obj, currentObjectKey.getNumber(), currentObjectKey.getGeneration()); } COSWriter.writeString(obj, getStandardOutput()); return null; }
if (dictionary == null) dictionary = new PDEncryption(); dictionary.setFilter(FILTER); dictionary.setLength(this.keyLength); int version = computeVersionNumber(); dictionary.setVersion(version); dictionary.removeV45filters(); if (version == 4 || version == 5) dictionary.setSubFilter(SUBFILTER5); mdResult = MessageDigests.getSHA256().digest(shaInput); COSName aesVName = version == 5 ? COSName.AESV3 : COSName.AESV2; dictionary.setSubFilter(SUBFILTER4); mdResult = MessageDigests.getSHA1().digest(shaInput); dictionary.setRecipients(recipientsFields); doc.getDocument().setEncryptionDictionary(dictionary.getCOSDictionary());
if(encryptionDictionary == null) encryptionDictionary = new PDEncryption(); encryptionDictionary.setFilter(FILTER); encryptionDictionary.setVersion(version); if (version != 4 && version != 5) encryptionDictionary.removeV45filters(); encryptionDictionary.setRevision(revision); encryptionDictionary.setLength(keyLength); encryptionDictionary.setPermissions(permissionInt); document.getDocument().setEncryptionDictionary(encryptionDictionary.getCOSDictionary());
encryption = new PDEncryption(); getEncryption().setSecurityHandler(securityHandler);
setDecryptMetadata(encryption.isEncryptMetaData()); if (encryption.getLength() != 0) this.keyLength = encryption.getLength(); COSArray array = (COSArray) encryption.getCOSDictionary().getItem(COSName.RECIPIENTS); if (array == null) PDCryptFilterDictionary defaultCryptFilterDictionary = encryption.getDefaultCryptFilterDictionary(); array = (COSArray) defaultCryptFilterDictionary.getCOSDictionary().getItem(COSName.RECIPIENTS); if (encryption.getVersion() == 4 || encryption.getVersion() == 5) PDCryptFilterDictionary defaultCryptFilterDictionary = encryption.getDefaultCryptFilterDictionary(); if (defaultCryptFilterDictionary != null)
setDecryptMetadata(encryption.isEncryptMetaData()); if (encryption.getLength() != 0) this.keyLength = encryption.getLength(); byte[][] recipientFieldsBytes = new byte[encryption.getRecipientsLength()][]; for (; i < encryption.getRecipientsLength(); i++) COSString recipientFieldString = encryption.getRecipientStringAt(i); byte[] recipientBytes = recipientFieldString.getBytes(); CMSEnvelopedData data = new CMSEnvelopedData(recipientBytes);
this.errors = new ArrayList<>(); try { this.ownerKey = new COSString(encryption.getOwnerKey()).toHexString(); } catch (IOException e) { LOGGER.debug("PDFBox error getting owner key data", e); this.userKey = new COSString(encryption.getUserKey()).toHexString(); } catch (IOException e) { LOGGER.debug("PDFBox error getting user key data", e); SecurityHandler securityHandler = encryption.getSecurityHandler(); this.isUserPermissionsPresent = securityHandler != null; if (securityHandler != null) { AccessPermission accessPermissions = new AccessPermission(encryption.getPermissions()); this.isPrintAllowed = accessPermissions.canPrint(); this.isPrintDegradedAllowed = accessPermissions.canPrintDegraded();
encryption = new PDEncryption(document.getEncryptionDictionary()); DecryptionMaterial decryptionMaterial; if (keyStoreInputStream != null) securityHandler = encryption.getSecurityHandler(); securityHandler.prepareForDecryption(encryption, document.getDocumentID(), decryptionMaterial);
@Override public int getVersion() { if (encryption != null) { return encryption.getVersion(); } return 0; }
@Override public int getLength() { if (encryption != null) { return encryption.getLength(); } return 0; }
@Override public boolean isEncryptMetadata() { return encryption == null || encryption.isEncryptMetaData(); } }
/** * This will get the encryption dictionary for this document. This will still return the parameters if the document * was decrypted. As the encryption architecture in PDF documents is plugable this returns an abstract class, * but the only supported subclass at this time is a * PDStandardEncryption object. * * @return The encryption dictionary(most likely a PDStandardEncryption object) */ public PDEncryption getEncryption() { if (encryption == null && isEncrypted()) { encryption = new PDEncryption(document.getEncryptionDictionary()); } return encryption; }
if (dictionary == null) dictionary = new PDEncryption(); dictionary.setFilter(FILTER); dictionary.setLength(this.keyLength); dictionary.setVersion(2); dictionary.removeV45filters(); dictionary.setSubFilter(SUBFILTER); dictionary.setRecipients(recipientsField); for(int j=0; j<dictionary.getRecipientsLength(); j++) COSString string = dictionary.getRecipientStringAt(j); sha1InputLength += string.getBytes().length; for(int j=0; j<dictionary.getRecipientsLength(); j++) COSString string = dictionary.getRecipientStringAt(j); System.arraycopy( string.getBytes(), 0, doc.getDocument().setEncryptionDictionary(dictionary.getCOSDictionary());
if(encryptionDictionary == null) encryptionDictionary = new PDEncryption(); encryptionDictionary.setFilter(FILTER); encryptionDictionary.setVersion(version); if (version != 4 && version != 5) encryptionDictionary.removeV45filters(); encryptionDictionary.setRevision(revision); encryptionDictionary.setLength(keyLength); encryptionDictionary.setPermissions(permissionInt); document.getDocument().setEncryptionDictionary(encryptionDictionary.getCOSDictionary());
setDecryptMetadata(encryption.isEncryptMetaData()); if (encryption.getLength() != 0) this.keyLength = encryption.getLength(); byte[][] recipientFieldsBytes = new byte[encryption.getRecipientsLength()][]; for (; i < encryption.getRecipientsLength(); i++) COSString recipientFieldString = encryption.getRecipientStringAt(i); byte[] recipientBytes = recipientFieldString.getBytes(); CMSEnvelopedData data = new CMSEnvelopedData(recipientBytes);
encryption = new PDEncryption(document.getEncryptionDictionary()); DecryptionMaterial decryptionMaterial; if (keyStoreInputStream != null) securityHandler = encryption.getSecurityHandler(); securityHandler.prepareForDecryption(encryption, document.getDocumentID(), decryptionMaterial);
encryption = new PDEncryption(); getEncryption().setSecurityHandler(securityHandler);
/** * This will get the encryption dictionary for this document. This will still return the parameters if the document * was decrypted. As the encryption architecture in PDF documents is plugable this returns an abstract class, * but the only supported subclass at this time is a * PDStandardEncryption object. * * @return The encryption dictionary(most likely a PDStandardEncryption object) */ public PDEncryption getEncryption() { if (encryption == null && isEncrypted()) { encryption = new PDEncryption(document.getEncryptionDictionary()); } return encryption; }