Class PdfEncryption
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfEncryption
-
public class PdfEncryption extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static intAES_128private ARCFOUREncryptionarcfourprivate intcryptoMode(package private) byte[]documentIDprivate booleanembeddedFilesOnlyprivate booleanencryptMetadata(package private) byte[]extraWork area to prepare the object/generation bytes(package private) byte[]keyThe encryption key for a particular object/generationprivate intkeyLengthThe generic key length.(package private) intkeySizeThe encryption key length for a particular object/generation(package private) java.security.MessageDigestmd5The message digest algorithm MD5private static byte[]metadataPad(package private) byte[]mkeyThe global encryption key(package private) byte[]ownerKeyThe encryption key for the ownerprivate static byte[]pad(package private) intpermissionsThe public key security handler for certificate encryptionprivate intrevisionprivate static byte[]salt(package private) static longseqstatic intSTANDARD_ENCRYPTION_128static intSTANDARD_ENCRYPTION_40(package private) byte[]state(package private) byte[]userKeyThe encryption key for the user(package private) intx(package private) inty
-
Constructor Summary
Constructors Constructor Description PdfEncryption()PdfEncryption(PdfEncryption enc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcalculateStreamSize(int n)private byte[]computeOwnerKey(byte[] userPad, byte[] ownerPad)byte[]computeUserPassword(byte[] ownerPassword)static byte[]createDocumentId()static PdfObjectcreateInfoId(byte[] id)byte[]decryptByteArray(byte[] b)byte[]encryptByteArray(byte[] b)voidencryptRC4(byte[] data)voidencryptRC4(byte[] dataIn, byte[] dataOut)voidencryptRC4(byte[] data, int off, int len)voidencryptRC4(byte[] dataIn, int off, int len, byte[] dataOut)intgetCryptoMode()StandardDecryptiongetDecryptor()PdfDictionarygetEncryptionDictionary()OutputStreamEncryptiongetEncryptionStream(java.io.OutputStream os)PdfObjectgetFileID()booleanisEmbeddedFilesOnly()Indicates if only the embedded files have to be encrypted.booleanisMetadataEncrypted()private byte[]padPassword(byte[] userPassword)voidprepareKey()voidprepareRC4Key(byte[] kk)voidprepareRC4Key(byte[] kk, int off, int len)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[] userKey, byte[] ownerKey, int permissions)private voidsetupByUserPad(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions)voidsetupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, int permissions)private voidsetupGlobalEncryptionKey(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions)ownerKey, documentID must be setupprivate voidsetupUserKey()mkey must be setup
-
-
-
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
-
pad
private static final byte[] pad
-
salt
private static final byte[] salt
-
metadataPad
private static final byte[] metadataPad
-
key
byte[] key
The encryption key for a particular object/generation
-
keySize
int keySize
The encryption key length for a particular object/generation
-
mkey
byte[] mkey
The global encryption key
-
extra
byte[] extra
Work area to prepare the object/generation bytes
-
md5
java.security.MessageDigest md5
The message digest algorithm MD5
-
ownerKey
byte[] ownerKey
The encryption key for the owner
-
userKey
byte[] userKey
The encryption key for the user
-
permissions
int permissions
The public key security handler for certificate encryption
-
documentID
byte[] documentID
-
seq
static long seq
-
revision
private int revision
-
arcfour
private ARCFOUREncryption arcfour
-
keyLength
private int keyLength
The generic key length. It may be 40 or 128.
-
encryptMetadata
private boolean encryptMetadata
-
embeddedFilesOnly
private boolean embeddedFilesOnly
-
cryptoMode
private int cryptoMode
-
state
byte[] state
-
x
int x
-
y
int y
-
-
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()
-
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)
-
createDocumentId
public static byte[] createDocumentId()
-
setupByUserPassword
public void setupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, int 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)
-
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)
-
createInfoId
public static PdfObject createInfoId(byte[] id)
-
getEncryptionDictionary
public PdfDictionary getEncryptionDictionary()
-
getFileID
public PdfObject getFileID()
-
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)
-
computeUserPassword
public byte[] computeUserPassword(byte[] ownerPassword)
-
prepareKey
public void prepareKey()
-
prepareRC4Key
public void prepareRC4Key(byte[] kk)
-
prepareRC4Key
public void prepareRC4Key(byte[] kk, int off, int len)
-
encryptRC4
public void encryptRC4(byte[] dataIn, int off, int len, byte[] dataOut)
-
encryptRC4
public void encryptRC4(byte[] data, int off, int len)
-
encryptRC4
public void encryptRC4(byte[] dataIn, byte[] dataOut)
-
encryptRC4
public void encryptRC4(byte[] data)
-
-