Class PdfEncryption
java.lang.Object
org.openpdf.text.pdf.PdfEncryption
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intprivate ARCFOUREncryptionprivate int(package private) byte[]private booleanIndicates if the encryption is only necessary for embedded files.private boolean(package private) byte[]Work area to prepare the object/generation bytes(package private) byte[]The encryption key for a particular object/generationprivate intThe generic key length.(package private) intThe encryption key length for a particular object/generation(package private) MessageDigestThe message digest algorithm MD5private static final byte[](package private) byte[]The global encryption key(package private) byte[]Additional keys for AES_256_V3(package private) byte[]The encryption key for the ownerprivate static final byte[](package private) int(package private) byte[]protected PdfPublicKeySecurityHandlerThe public key security handler for certificate encryptionprivate intprivate static final byte[](package private) static longstatic final intstatic final int(package private) byte[](package private) byte[]The encryption key for the user -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRecipient(Certificate cert, int permission) intcalculateStreamSize(int n) (package private) voidcomputeOAndOeAlg9(byte[] ownerPassword) implements Algorithm 9: Computing the encryption dictionary’s O (owner password) and OE (owner encryption) values (Security handlers of revision 6) - ISO 32000-2 section 7.6.4.4.8private byte[]computeOwnerKey(byte[] userPad, byte[] ownerPad) (package private) voidcomputePermsAlg10(int permissions) implements Algorithm 10: Computing the encryption dictionary’s Perms (permissions) value (Security handlers of revision 6) - ISO 32000-2 section 7.6.4.4.9(package private) voidcomputeUAndUeAlg8(byte[] userPassword) implements Algorithm 8: Computing the encryption dictionary’s U (user password) and UE (user encryption) values (Security handlers of revision 6) - ISO 32000-2 section 7.6.4.4.7byte[]computeUserPassword(byte[] ownerPassword) static byte[]static PdfObjectcreateInfoId(byte[] id) static PdfObjectcreateInfoId(byte[] idPartOne, byte[] idPartTwo) private static byte[]decodeHex(byte[] hexEncoded) booleandecryptAndCheckPerms(byte[] permsValue) 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.3byte[]decryptByteArray(byte[] b) byte[]encryptByteArray(byte[] b) intstatic byte[]getFileIdChangingPart(PdfObject fileId) This method returns a changing part of thefileIdwhen can be identified.(package private) byte[]hashAlg2B(byte[] input, byte[] salt, byte[] userKey) implements Algorithm 2.B: Computing a hash (revision 6 and later) - ISO 32000-2 section 7.6.4.3.4booleanIndicates if only the embedded files have to be encrypted.private static booleanisHexEncoded(byte[] str) booleanprivate byte[]padPassword(byte[] userPassword) voidsetCryptoMode(int mode, int kl) voidsetHashKey(int number, int generation) voidsetupAllKeys(byte[] userPassword, byte[] ownerPassword, int permissions) voidsetupByEncryptionKey(byte[] key, int keylength) private voidsetupByOwnerPad(byte[] documentID, byte[] ownerPad, byte[] userKey, byte[] ownerKey, int permissions) voidsetupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] uValue, byte[] ueValue, byte[] oValue, byte[] oeValue, int permissions) 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.3voidsetupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, int permissions) private voidsetupByUserPad(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions) voidsetupByUserPassword(byte[] documentID, byte[] userPassword, byte[] uValue, byte[] ueValue, byte[] oValue, byte[] oeValue, int permissions) 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.3voidsetupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, int permissions) private voidsetupGlobalEncryptionKey(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions) ownerKey, documentID must be setupprivate voidmkey must be setup
-
Field Details
-
STANDARD_ENCRYPTION_40
public static final int STANDARD_ENCRYPTION_40- See Also:
-
STANDARD_ENCRYPTION_128
public static final int STANDARD_ENCRYPTION_128- See Also:
-
AES_128
public static final int AES_128- See Also:
-
AES_256_V3
public static final int AES_256_V3- See Also:
-
pad
private static final byte[] pad -
salt
private static final byte[] salt -
metadataPad
private static final byte[] metadataPad -
seq
static long seq -
publicKeyHandler
The public key security handler for certificate encryption -
key
byte[] keyThe encryption key for a particular object/generation -
keySize
int keySizeThe encryption key length for a particular object/generation -
mkey
byte[] mkeyThe global encryption key -
extra
byte[] extraWork area to prepare the object/generation bytes -
md5
MessageDigest md5The message digest algorithm MD5 -
ownerKey
byte[] ownerKeyThe encryption key for the owner -
userKey
byte[] userKeyThe encryption key for the user -
oeKey
byte[] oeKeyAdditional keys for AES_256_V3 -
ueKey
byte[] ueKey -
perms
byte[] perms -
permissions
int permissions -
documentID
byte[] documentID -
revision
private int revision -
arcfour
-
keyLength
private int keyLengthThe generic key length. It may be 40 or 128. -
encryptMetadata
private boolean encryptMetadata -
embeddedFilesOnly
private boolean embeddedFilesOnlyIndicates if the encryption is only necessary for embedded files.- Since:
- 2.1.3
-
cryptoMode
private int cryptoMode
-
-
Constructor Details
-
PdfEncryption
public PdfEncryption() -
PdfEncryption
-
-
Method Details
-
createDocumentId
public static byte[] createDocumentId() -
createInfoId
-
createInfoId
-
getFileIdChangingPart
This method returns a changing part of thefileIdwhen can be identified. Returns a completefileIdof the changing part is not found.- Parameters:
fileId-PdfObject- Returns:
- byte array representing the changing part of the document identifier
-
isHexEncoded
private static boolean isHexEncoded(byte[] str) -
decodeHex
private static byte[] decodeHex(byte[] hexEncoded) -
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
-
padPassword
private byte[] padPassword(byte[] userPassword) -
computeOwnerKey
private byte[] computeOwnerKey(byte[] userPad, byte[] ownerPad) -
setupGlobalEncryptionKey
private void setupGlobalEncryptionKey(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions) ownerKey, documentID must be setup -
setupUserKey
private void setupUserKey()mkey must be setup -
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 iduserPassword- byte array of user passwordownerKey- byte array of owner keypermissions- permissions
-
setupByUserPad
private void setupByUserPad(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions) -
setupByOwnerPassword
public void setupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, int permissions) - Parameters:
documentID- byte array of document idownerPassword- byte array of owner passworduserKey- byte array of user keyownerKey- byte array of owner keypermissions- permissions
-
setupByOwnerPad
private void setupByOwnerPad(byte[] documentID, byte[] ownerPad, byte[] userKey, byte[] ownerKey, int permissions) -
setupByEncryptionKey
public void setupByEncryptionKey(byte[] key, int keylength) -
setHashKey
public void setHashKey(int number, int generation) -
getEncryptionDictionary
-
getFileID
-
getEncryptionStream
-
calculateStreamSize
public int calculateStreamSize(int n) -
encryptByteArray
public byte[] encryptByteArray(byte[] b) -
getDecryptor
-
decryptByteArray
public byte[] decryptByteArray(byte[] b) -
addRecipient
-
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
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
-
hashAlg2B
implements Algorithm 2.B: Computing a hash (revision 6 and later) - ISO 32000-2 section 7.6.4.3.4- Throws:
GeneralSecurityException
-
computeUAndUeAlg8
implements Algorithm 8: Computing the encryption dictionary’s U (user password) and UE (user encryption) values (Security handlers of revision 6) - ISO 32000-2 section 7.6.4.4.7- Throws:
GeneralSecurityException
-
computeOAndOeAlg9
implements Algorithm 9: Computing the encryption dictionary’s O (owner password) and OE (owner encryption) values (Security handlers of revision 6) - ISO 32000-2 section 7.6.4.4.8- Throws:
GeneralSecurityException
-
computePermsAlg10
implements Algorithm 10: Computing the encryption dictionary’s Perms (permissions) value (Security handlers of revision 6) - ISO 32000-2 section 7.6.4.4.9- Throws:
GeneralSecurityException
-