com.lowagie.text.pdf

Class PdfEncryption

public class PdfEncryption extends Object

Author: Paulo Soares (psoares@consiste.pt) Kazuya Ujihara

Field Summary
static intAES_128
ARCFOUREncryptionarcfour
intcryptoMode
byte[]documentID
booleanembeddedFilesOnly
Indicates if the encryption is only necessary for embedded files.
booleanencryptMetadata
byte[]extra
Work area to prepare the object/generation bytes
byte[]key
The encryption key for a particular object/generation
intkeyLength
The generic key length.
intkeySize
The encryption key length for a particular object/generation
MessageDigestmd5
The message digest algorithm MD5
static byte[]metadataPad
byte[]mkey
The global encryption key
byte[]ownerKey
The encryption key for the owner
static byte[]pad
intpermissions
protected PdfPublicKeySecurityHandlerpublicKeyHandler
The public key security handler for certificate encryption
intrevision
static byte[]salt
static longseq
static intSTANDARD_ENCRYPTION_128
static intSTANDARD_ENCRYPTION_40
byte[]userKey
The encryption key for the user
Constructor Summary
PdfEncryption()
PdfEncryption(PdfEncryption enc)
Method Summary
voidaddRecipient(Certificate cert, int permission)
intcalculateStreamSize(int n)
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)
intgetCryptoMode()
StandardDecryptiongetDecryptor()
PdfDictionarygetEncryptionDictionary()
OutputStreamEncryptiongetEncryptionStream(OutputStream os)
PdfObjectgetFileID()
booleanisEmbeddedFilesOnly()
Indicates if only the embedded files have to be encrypted.
booleanisMetadataEncrypted()
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)
voidsetupByOwnerPad(byte[] documentID, byte[] ownerPad, byte[] userKey, byte[] ownerKey, int permissions)
voidsetupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, int permissions)
voidsetupByUserPad(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions)
voidsetupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, int permissions)
voidsetupGlobalEncryptionKey(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions)
ownerKey, documentID must be setup
voidsetupUserKey()
mkey must be setup

Field Detail

AES_128

public static final int AES_128

arcfour

private ARCFOUREncryption arcfour

cryptoMode

private int cryptoMode

documentID

byte[] documentID

embeddedFilesOnly

private boolean embeddedFilesOnly
Indicates if the encryption is only necessary for embedded files.

Since: 2.1.3

encryptMetadata

private boolean encryptMetadata

extra

byte[] extra
Work area to prepare the object/generation bytes

key

byte[] key
The encryption key for a particular object/generation

keyLength

private int keyLength
The generic key length. It may be 40 or 128.

keySize

int keySize
The encryption key length for a particular object/generation

md5

MessageDigest md5
The message digest algorithm MD5

metadataPad

private static final byte[] metadataPad

mkey

byte[] mkey
The global encryption key

ownerKey

byte[] ownerKey
The encryption key for the owner

pad

private static final byte[] pad

permissions

int permissions

publicKeyHandler

protected PdfPublicKeySecurityHandler publicKeyHandler
The public key security handler for certificate encryption

revision

private int revision

salt

private static final byte[] salt

seq

static long seq

STANDARD_ENCRYPTION_128

public static final int STANDARD_ENCRYPTION_128

STANDARD_ENCRYPTION_40

public static final int STANDARD_ENCRYPTION_40

userKey

byte[] userKey
The encryption key for the user

Constructor Detail

PdfEncryption

public PdfEncryption()

PdfEncryption

public PdfEncryption(PdfEncryption enc)

Method Detail

addRecipient

public void addRecipient(Certificate cert, int permission)

calculateStreamSize

public int calculateStreamSize(int n)

computeOwnerKey

private byte[] computeOwnerKey(byte[] userPad, byte[] ownerPad)

computeUserPassword

public byte[] computeUserPassword(byte[] ownerPassword)

createDocumentId

public static byte[] createDocumentId()

createInfoId

public static PdfObject createInfoId(byte[] id)

decryptByteArray

public byte[] decryptByteArray(byte[] b)

encryptByteArray

public byte[] encryptByteArray(byte[] b)

getCryptoMode

public int getCryptoMode()

getDecryptor

public StandardDecryption getDecryptor()

getEncryptionDictionary

public PdfDictionary getEncryptionDictionary()

getEncryptionStream

public OutputStreamEncryption getEncryptionStream(OutputStream os)

getFileID

public PdfObject getFileID()

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

isMetadataEncrypted

public boolean isMetadataEncrypted()

padPassword

private byte[] padPassword(byte[] userPassword)

setCryptoMode

public void setCryptoMode(int mode, int kl)

setHashKey

public void setHashKey(int number, int generation)

setupAllKeys

public void setupAllKeys(byte[] userPassword, byte[] ownerPassword, int permissions)

setupByEncryptionKey

public void setupByEncryptionKey(byte[] key, int keylength)

setupByOwnerPad

private void setupByOwnerPad(byte[] documentID, byte[] ownerPad, byte[] userKey, byte[] ownerKey, int permissions)

setupByOwnerPassword

public void setupByOwnerPassword(byte[] documentID, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, int permissions)

setupByUserPad

private void setupByUserPad(byte[] documentID, byte[] userPad, byte[] ownerKey, int permissions)

setupByUserPassword

public void setupByUserPassword(byte[] documentID, byte[] userPassword, byte[] ownerKey, int permissions)

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