Package com.itextpdf.text.pdf
Class PdfEncryption
- java.lang.Object
-
- com.itextpdf.text.pdf.PdfEncryption
-
public class PdfEncryption extends java.lang.Object
- Author:
- Paulo Soares, Kazuya Ujihara
-
-
Field Summary
Fields Modifier and Type Field Description static int
AES_128
static int
AES_256
protected PdfPublicKeySecurityHandler
publicKeyHandler
The public key security handler for certificate encryptionstatic int
STANDARD_ENCRYPTION_128
static int
STANDARD_ENCRYPTION_40
-
Constructor Summary
Constructors Constructor Description PdfEncryption()
PdfEncryption(PdfEncryption enc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRecipient(java.security.cert.Certificate cert, int permission)
int
calculateStreamSize(int n)
byte[]
computeUserPassword(byte[] ownerPassword)
Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 algorithm (Revision 2 - 4).static byte[]
createDocumentId()
static PdfObject
createInfoId(byte[] id, boolean modified)
byte[]
decryptByteArray(byte[] b)
byte[]
encryptByteArray(byte[] b)
int
getCryptoMode()
StandardDecryption
getDecryptor()
PdfDictionary
getEncryptionDictionary()
OutputStreamEncryption
getEncryptionStream(java.io.OutputStream os)
PdfObject
getFileID(boolean modified)
long
getPermissions()
boolean
isEmbeddedFilesOnly()
Indicates if only the embedded files have to be encrypted.boolean
isMetadataEncrypted()
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)
void
setupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, long permissions)
void
setupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, long permissions)
-
-
-
Field Detail
-
STANDARD_ENCRYPTION_40
public static final int STANDARD_ENCRYPTION_40
- See Also:
- Constant Field Values
-
STANDARD_ENCRYPTION_128
public static final int STANDARD_ENCRYPTION_128
- See Also:
- Constant Field Values
-
AES_128
public static final int AES_128
- See Also:
- Constant Field Values
-
AES_256
public static final int AES_256
- See Also:
- Constant Field Values
-
publicKeyHandler
protected PdfPublicKeySecurityHandler publicKeyHandler
The public key security handler for certificate encryption
-
-
Constructor Detail
-
PdfEncryption
public PdfEncryption()
-
PdfEncryption
public PdfEncryption(PdfEncryption enc)
-
-
Method Detail
-
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
-
setupAllKeys
public void setupAllKeys(byte[] userPassword, byte[] ownerPassword, int permissions)
-
readKey
public boolean readKey(PdfDictionary enc, byte[] password) throws BadPasswordException
- Throws:
BadPasswordException
-
createDocumentId
public static byte[] createDocumentId()
-
setupByUserPassword
public void setupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, long permissions)
-
setupByOwnerPassword
public void setupByOwnerPassword(byte[] documentID, byte[] ownerPassword, 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
public static PdfObject createInfoId(byte[] id, boolean modified) throws java.io.IOException
- Throws:
java.io.IOException
-
getEncryptionDictionary
public PdfDictionary getEncryptionDictionary()
-
getFileID
public PdfObject getFileID(boolean modified) throws java.io.IOException
- Throws:
java.io.IOException
-
getEncryptionStream
public OutputStreamEncryption getEncryptionStream(java.io.OutputStream os)
-
calculateStreamSize
public int calculateStreamSize(int n)
-
encryptByteArray
public byte[] encryptByteArray(byte[] b)
-
getDecryptor
public StandardDecryption getDecryptor()
-
decryptByteArray
public byte[] decryptByteArray(byte[] b)
-
addRecipient
public void addRecipient(java.security.cert.Certificate cert, int permission)
-
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.
-
-