Package org.apache.fop.pdf
Class PDFEncryptionJCE
java.lang.Object
org.apache.fop.pdf.PDFObject
org.apache.fop.pdf.PDFEncryptionJCE
- All Implemented Interfaces:
PDFEncryption,PDFWritable
An implementation of the Standard Security Handler.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate classprivate static final classprivate classprivate static enumprivate classprivate classprivate classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MessageDigestprivate Stringprivate byte[]private booleanprivate static byte[]private Versionprivate SecureRandomprivate boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePDFEncryptionJCE(PDFObjectNumber objectNumber, PDFEncryptionParams params, PDFDocument pdf) -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyFilter(AbstractPDFStream stream) Adds a PDFFilter to the PDFStream objectprivate byte[]createEncryptionKey(int objectNumber, int generationNumber) Applies Algorithm 3.1 from the PDF 1.4 Reference.byte[]Encrypt an array of bytes using a reference PDFObject for calculating the encryption key.private static byte[]encryptWithKey(byte[] key, byte[] data) private static byte[]encryptWithKey(byte[] key, byte[] data, boolean noPadding, byte[] iv) Returns the PDF version required by the current encryption algorithm.Returns the /Encrypt entry in the file trailer dictionary.private static CipherinitCipher(byte[] key) private static CipherinitCipher(byte[] key, boolean noPadding, byte[] iv) static PDFEncryptionmake(PDFObjectNumber objectNumber, PDFEncryptionParams params, PDFDocument pdf) Creates and returns an encryption object.private byte[]prepareMD5Input(int objectNumber, int generationNumber) byte[]toPDF()Prepares the encryption dictionary for output to a PDF file.Methods inherited from class org.apache.fop.pdf.PDFObject
contentEquals, encode, encodeBinaryToHexString, encodeString, encodeText, formatObject, getChildren, getDocument, getDocumentSafely, getGeneration, getObjectID, getObjectNumber, getParent, hasObjectNumber, makeReference, output, outputInline, referencePDF, setDocument, setObjectNumber, setObjectNumber, setObjectNumber, setParent, toPDFString
-
Field Details
-
digest
-
random
-
encryptionKey
private byte[] encryptionKey -
encryptionDictionary
-
useAlgorithm31a
private boolean useAlgorithm31a -
encryptMetadata
private boolean encryptMetadata -
pdfVersion
-
ivZero
private static byte[] ivZero
-
-
Constructor Details
-
PDFEncryptionJCE
-
-
Method Details
-
make
public static PDFEncryption make(PDFObjectNumber objectNumber, PDFEncryptionParams params, PDFDocument pdf) Creates and returns an encryption object.- Parameters:
objectNumber- the object number for the encryption dictionaryparams- the encryption parameterspdf- the PDF document to be encrypted- Returns:
- the newly created encryption object
-
encrypt
Encrypt an array of bytes using a reference PDFObject for calculating the encryption key.- Specified by:
encryptin interfacePDFEncryption- Parameters:
data- data to encryptrefObj- reference PDFObject- Returns:
- byte[] the encrypted data
-
applyFilter
Adds a PDFFilter to the PDFStream object- Specified by:
applyFilterin interfacePDFEncryption- Parameters:
stream- the stream to add an encryption filter to
-
toPDF
public byte[] toPDF()Prepares the encryption dictionary for output to a PDF file. -
getTrailerEntry
Returns the /Encrypt entry in the file trailer dictionary.- Specified by:
getTrailerEntryin interfacePDFEncryption- Returns:
- the string "/Encrypt n g R\n" where n and g are the number and generation of the document's encryption dictionary
-
encryptWithKey
private static byte[] encryptWithKey(byte[] key, byte[] data) -
encryptWithKey
private static byte[] encryptWithKey(byte[] key, byte[] data, boolean noPadding, byte[] iv) -
initCipher
-
initCipher
-
createEncryptionKey
private byte[] createEncryptionKey(int objectNumber, int generationNumber) Applies Algorithm 3.1 from the PDF 1.4 Reference.- Parameters:
objectNumber- the object numbergenerationNumber- the generation number- Returns:
- the key to use for encryption
-
prepareMD5Input
private byte[] prepareMD5Input(int objectNumber, int generationNumber) -
getPDFVersion
Returns the PDF version required by the current encryption algorithm.- Specified by:
getPDFVersionin interfacePDFEncryption- Returns:
- the PDF Version
-