Package com.itextpdf.text.pdf
Class PdfEncryption
java.lang.Object
com.itextpdf.text.pdf.PdfEncryption
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
private ARCFOUREncryption
private int
(package private) byte[]
private boolean
Indicates 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 static final int
private int
The generic key length.(package private) int
The encryption key length for a particular object/generation(package private) MessageDigest
The message digest algorithm MD5private static final byte[]
(package private) byte[]
The global encryption key(package private) byte[]
private static final int
(package private) byte[]
The encryption key for the ownerprivate static final byte[]
(package private) long
(package private) byte[]
protected PdfPublicKeySecurityHandler
The public key security handler for certificate encryptionprivate int
private static final byte[]
private static final int
(package private) static long
static final int
static final int
(package private) byte[]
(package private) byte[]
The encryption key for the userprivate static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRecipient
(Certificate cert, int permission) int
calculateStreamSize
(int n) private static boolean
compareArray
(byte[] a, byte[] b, int len) private byte[]
computeOwnerKey
(byte[] userPad, byte[] ownerPad) byte[]
computeUserPassword
(byte[] ownerPassword) Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 algorithm (Revision 2 - 4).static byte[]
static PdfObject
createInfoId
(byte[] id, boolean modified) byte[]
decryptByteArray
(byte[] b) byte[]
encryptByteArray
(byte[] b) int
getFileID
(boolean modified) long
boolean
Indicates if only the embedded files have to be encrypted.boolean
private byte[]
padPassword
(byte[] userPassword) boolean
readKey
(PdfDictionary enc, byte[] password) void
setCryptoMode
(int mode, int kl) void
setHashKey
(int number, int generation) void
setKey
(byte[] key) void
setupAllKeys
(byte[] userPassword, byte[] ownerPassword, int permissions) void
setupByEncryptionKey
(byte[] key, int keylength) private void
setupByOwnerPad
(byte[] documentID, byte[] ownerPad, byte[] userKey, byte[] ownerKey, long permissions) void
setupByOwnerPassword
(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, long permissions) private void
setupByUserPad
(byte[] documentID, byte[] userPad, byte[] ownerKey, long permissions) void
setupByUserPassword
(byte[] documentID, byte[] userPassword, byte[] ownerKey, long permissions) private void
setupGlobalEncryptionKey
(byte[] documentID, byte[] userPad, byte[] ownerKey, long permissions) ownerKey, documentID must be setupprivate void
mkey 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
public static final int AES_256- See Also:
-
pad
private static final byte[] pad -
salt
private static final byte[] salt -
metadataPad
private static final byte[] metadataPad -
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 -
ownerKey
byte[] ownerKeyThe encryption key for the owner -
userKey
byte[] userKeyThe encryption key for the user -
oeKey
byte[] oeKey -
ueKey
byte[] ueKey -
perms
byte[] perms -
permissions
long permissions -
documentID
byte[] documentID -
revision
private int revision -
keyLength
private int keyLengthThe generic key length. It may be 40 or 128. -
publicKeyHandler
The public key security handler for certificate encryption -
extra
byte[] extraWork area to prepare the object/generation bytes -
md5
MessageDigest md5The message digest algorithm MD5 -
arcfour
-
encryptMetadata
private boolean encryptMetadata -
seq
static long seq -
embeddedFilesOnly
private boolean embeddedFilesOnlyIndicates if the encryption is only necessary for embedded files.- Since:
- 2.1.3
-
cryptoMode
private int cryptoMode -
VALIDATION_SALT_OFFSET
private static final int VALIDATION_SALT_OFFSET- See Also:
-
KEY_SALT_OFFSET
private static final int KEY_SALT_OFFSET- See Also:
-
SALT_LENGHT
private static final int SALT_LENGHT- See Also:
-
OU_LENGHT
private static final int OU_LENGHT- See Also:
-
-
Constructor Details
-
PdfEncryption
public PdfEncryption() -
PdfEncryption
-
-
Method Details
-
setCryptoMode
public void setCryptoMode(int mode, int kl) -
getCryptoMode
public int getCryptoMode() -
isMetadataEncrypted
public boolean isMetadataEncrypted() -
getPermissions
public long getPermissions() -
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, long permissions) ownerKey, documentID must be setup -
setupUserKey
private void setupUserKey()mkey must be setup -
setupAllKeys
public void setupAllKeys(byte[] userPassword, byte[] ownerPassword, int permissions) -
readKey
- Throws:
BadPasswordException
-
compareArray
private static boolean compareArray(byte[] a, byte[] b, int len) -
createDocumentId
public static byte[] createDocumentId() -
setupByUserPassword
public void setupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, long permissions) -
setupByUserPad
private void setupByUserPad(byte[] documentID, byte[] userPad, byte[] ownerKey, long permissions) -
setupByOwnerPassword
public void setupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, long permissions) -
setupByOwnerPad
private void setupByOwnerPad(byte[] documentID, byte[] ownerPad, byte[] userKey, byte[] ownerKey, long permissions) -
setKey
public void setKey(byte[] key) -
setupByEncryptionKey
public void setupByEncryptionKey(byte[] key, int keylength) -
setHashKey
public void setHashKey(int number, int generation) -
createInfoId
- Throws:
IOException
-
getEncryptionDictionary
-
getFileID
- Throws:
IOException
-
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) Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 algorithm (Revision 2 - 4).- Parameters:
ownerPassword
- owner password of the encrypted document.- Returns:
- user password, or null if revision 5 (AES256) or greater of standard encryption handler was used.
-