private void prepareEncryptionDictAES(PDEncryption encryptionDictionary, COSName aesVName) { PDCryptFilterDictionary cryptFilterDictionary = new PDCryptFilterDictionary(); cryptFilterDictionary.setCryptFilterMethod(aesVName); cryptFilterDictionary.setLength(keyLength); encryptionDictionary.setStdCryptFilterDictionary(cryptFilterDictionary); encryptionDictionary.setStreamFilterName(COSName.STD_CF); encryptionDictionary.setStringFilterName(COSName.STD_CF); setAES(true); }
/** * creates a new encryption dictionary from the low level dictionary provided. * @param dictionary a COS encryption dictionary */ public PDEncryption(COSDictionary dictionary) { this.dictionary = dictionary; securityHandler = SecurityHandlerFactory.INSTANCE.newSecurityHandlerForFilter(getFilter()); }
/** * This will tell if the user can print. * * @return true If supplied with the user password they are allowed to print. */ public boolean canPrint() { return isPermissionBitOn( PRINT_BIT ); }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * Sets the standard crypt filter. * * @param cryptFilterDictionary the standard crypt filter to set */ public void setStdCryptFilterDictionary(PDCryptFilterDictionary cryptFilterDictionary) { setCryptFilterDictionary(COSName.STD_CF, cryptFilterDictionary); }
/** * Returns the standard crypt filter. * * @return the standard crypt filter if available. */ public PDCryptFilterDictionary getStdCryptFilterDictionary() { return getCryptFilterDictionary(COSName.STD_CF); }
/** * Set if the user can modify the document. * <p> * This method will have no effect if the object is in read only mode. * * @param allowModifications A boolean determining if the user can modify the document. */ public void setCanModify( boolean allowModifications ) { if(!readOnly) { setPermissionBit( MODIFICATION_BIT, allowModifications ); } }
/** * Constructor used for encryption. * * @param p The protection policy. */ public PublicKeySecurityHandler(PublicKeyProtectionPolicy p) { policy = p; this.keyLength = policy.getEncryptionKeyLength(); }
/** * Constructor used for encryption. * * @param p The protection policy. */ public StandardSecurityHandler(StandardProtectionPolicy p) { policy = p; keyLength = policy.getEncryptionKeyLength(); }
private SecurityHandlerFactory() { registerHandler(StandardSecurityHandler.FILTER, StandardSecurityHandler.class, StandardProtectionPolicy.class); registerHandler(PublicKeySecurityHandler.FILTER, PublicKeySecurityHandler.class, PublicKeyProtectionPolicy.class); }
/** * This will tell if the user can extract text and images from the PDF document * for accessibility purposes. * * @return true If supplied with the user password they are allowed to extract content * from the PDF document */ public boolean canExtractForAccessibility() { return isPermissionBitOn( EXTRACT_FOR_ACCESSIBILITY_BIT ); }
/** * Sets the default crypt filter (for public-key security handler). * * @param defaultFilterDictionary the standard crypt filter to set */ public void setDefaultCryptFilterDictionary(PDCryptFilterDictionary defaultFilterDictionary) { setCryptFilterDictionary(COSName.DEFAULT_CRYPT_FILTER, defaultFilterDictionary); }
/** * Returns the default crypt filter (for public-key security handler). * * @return the default crypt filter if available. */ public PDCryptFilterDictionary getDefaultCryptFilterDictionary() { return getCryptFilterDictionary(COSName.DEFAULT_CRYPT_FILTER); }
/** * Set if the user can insert/rotate/delete pages. * <p> * This method will have no effect if the object is in read only mode. * * @param allowAssembly A boolean determining if the user can assemble the document. */ public void setCanAssembleDocument( boolean allowAssembly ) { if(!readOnly) { setPermissionBit( ASSEMBLE_DOCUMENT_BIT, allowAssembly ); } }
/** * This will tell if the user can insert/rotate/delete pages. * * @return true If supplied with the user password they are allowed to extract content * from the PDF document */ public boolean canAssembleDocument() { return isPermissionBitOn( ASSEMBLE_DOCUMENT_BIT ); }
/** * This will tell if the user can print the document in a degraded format. * * @return true If supplied with the user password they are allowed to print the * document in a degraded format. */ public boolean canPrintDegraded() { return isPermissionBitOn( DEGRADED_PRINT_BIT ); }
/** * This will tell if the user can modify contents of the document. * * @return true If supplied with the user password they are allowed to modify the document */ public boolean canModify() { return isPermissionBitOn( MODIFICATION_BIT ); }
/** * This will tell if the user can extract text and images from the PDF document. * * @return true If supplied with the user password they are allowed to extract content * from the PDF document */ public boolean canExtractContent() { return isPermissionBitOn( EXTRACT_BIT ); }
/** * This will tell if the user can fill in interactive form fields (including signature fields) * even if {@link #canModifyAnnotations() canModifyAnnotations()} returns false. * * @return true If supplied with the user password they are allowed to fill in form fields. */ public boolean canFillInForm() { return isPermissionBitOn( FILL_IN_FORM_BIT ); }
/** * This will tell if the user can add or modify text annotations and fill in interactive forms * fields and, if {@link #canModify() canModify()} returns true, create or modify interactive * form fields (including signature fields). Note that if * {@link #canFillInForm() canFillInForm()} returns true, it is still possible to fill in * interactive forms (including signature fields) even if this method here returns false. * * @return true If supplied with the user password they are allowed to modify annotations. */ public boolean canModifyAnnotations() { return isPermissionBitOn( MODIFY_ANNOTATIONS_BIT ); }