PoDoFo::PdfEncrypt Class Reference

#include <PdfEncrypt.h>

Inheritance diagram for PoDoFo::PdfEncrypt:

PoDoFo::PdfEncryptAES PoDoFo::PdfEncryptRC4

List of all members.

Public Types

enum  EPdfKeyLength
enum  EPdfPermissions {
  ePdfPermissions_Print = 0x00000004, ePdfPermissions_Edit = 0x00000008, ePdfPermissions_Copy = 0x00000010, ePdfPermissions_EditNotes = 0x00000020,
  ePdfPermissions_FillAndSign = 0x00000100, ePdfPermissions_Accessible = 0x00000200, ePdfPermissions_DocAssembly = 0x00000400, ePdfPermissions_HighPrint = 0x00000800
}
enum  EPdfEncryptAlgorithm { ePdfEncryptAlgorithm_RC4V1, ePdfEncryptAlgorithm_RC4V2, ePdfEncryptAlgorithm_AESV2 }

Public Member Functions

virtual ~PdfEncrypt ()
const PdfEncryptoperator= (const PdfEncrypt &rhs)
void GenerateEncryptionKey (const PdfString &documentId)
virtual void CreateEncryptionDictionary (PdfDictionary &rDictionary) const =0
virtual PdfOutputStreamCreateEncryptionOutputStream (PdfOutputStream *pOutputStream)=0
virtual PdfInputStreamCreateEncryptionInputStream (PdfInputStream *pInputStream)=0
bool Authenticate (const std::string &password, const PdfString &documentId)
bool IsPrintAllowed () const
bool IsEditAllowed () const
bool IsCopyAllowed () const
bool IsEditNotesAllowed () const
bool IsFillAndSignAllowed () const
bool IsAccessibilityAllowed () const
bool IsDocAssemblyAllowed () const
bool IsHighPrintAllowed () const
const unsigned char * GetUValue () const
 Get the U object value (user).
const unsigned char * GetOValue () const
 Get the O object value (owner).
int GetPValue () const
 Get the P object value (protection).
int GetRevision () const
 Get the revision number of the encryption method.
int GetKeyLength () const
 Get the key length of the encryption key in bits.
void Encrypt (std::string &str, int inputLen) const
 Encrypt a wxString.
virtual void Encrypt (unsigned char *str, int len) const =0
 Encrypt a character string.
virtual int CalculateStreamLength (int length) const
 Calculate stream size.
virtual int CalculateStreamOffset () const
 Calculate stream offset.
void SetCurrentReference (const PdfReference &rRef)

Static Public Member Functions

static PdfEncryptCreatePdfEncrypt (const std::string &userPassword, const std::string &ownerPassword, int protection=ePdfPermissions_Print|ePdfPermissions_Edit|ePdfPermissions_Copy|ePdfPermissions_EditNotes|ePdfPermissions_FillAndSign|ePdfPermissions_Accessible|ePdfPermissions_DocAssembly|ePdfPermissions_HighPrint, EPdfEncryptAlgorithm eAlgorithm=ePdfEncryptAlgorithm_RC4V1, EPdfKeyLength eKeyLength=ePdfKeyLength_40)
static PdfEncryptCreatePdfEncrypt (const PdfObject *pObject)
static PdfEncryptCreatePdfEncrypt (const PdfEncrypt &rhs)
static PdfString GetMD5String (const unsigned char *pBuffer, int nLength)

Protected Member Functions

void PadPassword (const std::string &password, unsigned char pswd[32])
 Pad a password to 32 characters.
void ComputeOwnerKey (unsigned char userPad[32], unsigned char ownerPad[32], int keylength, int revision, bool authenticate, unsigned char ownerKey[32])
 Compute owner key.
void ComputeEncryptionKey (const std::string &documentID, unsigned char userPad[32], unsigned char ownerKey[32], int pValue, int keyLength, int revision, unsigned char userKey[32])
 Compute encryption key and user key.
bool CheckKey (unsigned char key1[32], unsigned char key2[32])
 Check two keys for equality.
void RC4 (unsigned char *key, int keylen, unsigned char *textin, int textlen, unsigned char *textout)
 RC4 encryption.
void GenerateInitialVector (unsigned char iv[16])
 Generate initial vector.
void CreateObjKey (unsigned char objkey[16], int *pnKeyLen) const

Static Protected Member Functions

static void GetMD5Binary (const unsigned char *data, int length, unsigned char *digest)
 Calculate the binary MD5 message digest of the given data.

Protected Attributes

EPdfEncryptAlgorithm m_eAlgorithm
 The used encryption algorithm.
int m_keyLength
 Length of encryption key.
int m_rValue
 Revision.
int m_pValue
 P entry in pdf document.
EPdfKeyLength m_eKeyLength
 The key length.
std::string m_userPass
 User password.
std::string m_ownerPass
 Owner password.
unsigned char m_rc4key [16]
 last RC4 key
unsigned char m_rc4last [256]
 last RC4 state table
unsigned char m_uValue [32]
 U entry in pdf document.
unsigned char m_oValue [32]
 O entry in pdf document.


Detailed Description

Class representing PDF encryption methods. (For internal use only) Based on code from Ulrich Telle: http://wxcode.sourceforge.net/components/wxpdfdoc/ Original Copyright header: A class that is used to encrypt a PDF file and set document permisions on the PDF file.

As a user of this class, you have only to instanciate a object of this class and pass it to PdfWriter, PdfMemDocument, PdfStreamedDocument or PdfImmediateWriter. You do not have to call any other method of this class. The above classes know how to handle encryption using Pdfencrypt.


Member Enumeration Documentation

Enumerator:
ePdfEncryptAlgorithm_RC4V1  RC4 Version 1 encryption using a 40bit key.
ePdfEncryptAlgorithm_RC4V2  RC4 Version 2 encryption using a key with 40-128bit.
ePdfEncryptAlgorithm_AESV2  AES encryption with an 128 bit key (PDF1.6).

A enum specifying a valid keylength for a PDF encryption key. Keys must be in the range 40 to 128 bit and have to be a multiple of 8.

Adobe Reader supports only keys with 40 or 128bit!

Set user permissions/restrictions on a document

Enumerator:
ePdfPermissions_Print  Allow printing the document.
ePdfPermissions_Edit  Allow modifying the document besides annotations, form fields or chaning pages.
ePdfPermissions_Copy  Allow text and graphic extraction.
ePdfPermissions_EditNotes  Add or modify text annoations or form fields (if ePdfPermissions_Edit is set also allow to create interactive form fields including signature).
ePdfPermissions_FillAndSign  Fill in existing form or signature fields.
ePdfPermissions_Accessible  Extract text and graphics to support user with disabillities.
ePdfPermissions_DocAssembly  Assemble the document: insert, create, rotate delete pages or add bookmarks.
ePdfPermissions_HighPrint  Print a high resolution version of the document.


Constructor & Destructor Documentation

PoDoFo::PdfEncrypt::~PdfEncrypt (  )  [virtual]

Destruct the PdfEncrypt object


Member Function Documentation

bool PoDoFo::PdfEncrypt::Authenticate ( const std::string &  password,
const PdfString documentId 
)

Tries to authenticate a user using either the user or owner password

Parameters:
password owner or user password
documentId the documentId of the PDF file
Returns:
true if either the owner or user password matches password

virtual void PoDoFo::PdfEncrypt::CreateEncryptionDictionary ( PdfDictionary &  rDictionary  )  const [pure virtual]

Fill all keys into a encryption dictionary. This dictionary is usually added to the PDF files trailer under the /Encryption key.

Parameters:
rDictionary an empty dictionary which is filled with information about the used encryption algorithm

Implemented in PoDoFo::PdfEncryptAES, and PoDoFo::PdfEncryptRC4.

virtual PdfInputStream* PoDoFo::PdfEncrypt::CreateEncryptionInputStream ( PdfInputStream pInputStream  )  [pure virtual]

Create a PdfInputStream that decrypts all data read from it using the current settings of the PdfEncrypt object.

Warning: Currently only RC4 based encryption is supported using output streams!

Parameters:
pInputStream the created PdfInputStream reads all decrypted data to this input stream.
Returns:
a PdfInputStream that decrypts all data.

Implemented in PoDoFo::PdfEncryptAES, and PoDoFo::PdfEncryptRC4.

virtual PdfOutputStream* PoDoFo::PdfEncrypt::CreateEncryptionOutputStream ( PdfOutputStream pOutputStream  )  [pure virtual]

Create a PdfOutputStream that encrypts all data written to it using the current settings of the PdfEncrypt object.

Warning: Currently only RC4 based encryption is supported using output streams!

Parameters:
pOutputStream the created PdfOutputStream writes all encrypted data to this output stream.
Returns:
a PdfOutputStream that encryts all data.

Implemented in PoDoFo::PdfEncryptAES, and PoDoFo::PdfEncryptRC4.

void PoDoFo::PdfEncrypt::CreateObjKey ( unsigned char  objkey[16],
int *  pnKeyLen 
) const [protected]

Create the encryption key for the current object.

Parameters:
pObjkey pointer to an array of at least MD5_HASHBYTES (=16) bytes length
pnKeyLen pointer to an integer where the actual keylength is stored.

PdfEncrypt * PoDoFo::PdfEncrypt::CreatePdfEncrypt ( const PdfEncrypt rhs  )  [static]

Copy constructor

Parameters:
rhs another PdfEncrypt object which is copied

PdfEncrypt * PoDoFo::PdfEncrypt::CreatePdfEncrypt ( const PdfObject pObject  )  [static]

Initialize a PdfEncrypt object from an encryption dictionary in a PDF file.

This is required for encrypting a PDF file, but handled internally in PdfParser for you.

Parameters:
pObject a PDF encryption dictionary

PdfEncrypt * PoDoFo::PdfEncrypt::CreatePdfEncrypt ( const std::string &  userPassword,
const std::string &  ownerPassword,
int  protection = ePdfPermissions_Print | ePdfPermissions_Edit | ePdfPermissions_Copy | ePdfPermissions_EditNotes | ePdfPermissions_FillAndSign | ePdfPermissions_Accessible | ePdfPermissions_DocAssembly | ePdfPermissions_HighPrint,
EPdfEncryptAlgorithm  eAlgorithm = ePdfEncryptAlgorithm_RC4V1,
EPdfKeyLength  eKeyLength = ePdfKeyLength_40 
) [static]

Create a PdfEncrypt object which can be used to encrypt a PDF file.

Parameters:
userPassword the user password (if empty the user does not have to enter a password to open the document)
ownerPassword the owner password
protection several EPdfPermissions values or'ed together to set the users permissions for this document
eRevision the revision of the encryption algorithm to be used
eKeyLength the length of the encryption key ranging from 40 to 128 bits (only used if eAlgorithm == ePdfEncryptAlgorithm_RC4V2)
See also:
GenerateEncryptionKey with the documentID to generate the real encryption key using this information

void PoDoFo::PdfEncrypt::GenerateEncryptionKey ( const PdfString documentId  ) 

Generate encryption key from user and owner passwords and protection key

Parameters:
documentId the documentId of the current document

PdfString PoDoFo::PdfEncrypt::GetMD5String ( const unsigned char *  pBuffer,
int  nLength 
) [static]

Create a PdfString of MD5 data generated from a buffer in memory.

Parameters:
pBuffer the buffer of which to calculate the MD5 sum
nLength the length of the buffer
Returns:
an MD5 sum as PdfString

bool PoDoFo::PdfEncrypt::IsAccessibilityAllowed (  )  const [inline]

Checks if it is allowed to extract text and graphics to support users with disabillities Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to extract text and graphics to support users with disabillities
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsCopyAllowed (  )  const [inline]

Checks if text and graphics extraction is allowed. Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to extract text and graphics from this document
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsDocAssemblyAllowed (  )  const [inline]

Checks if it is allowed to insert, create, rotate, delete pages or add bookmarks Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to insert, create, rotate, delete pages or add bookmarks
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsEditAllowed (  )  const [inline]

Checks if modifiying this document (besides annotations, form fields or changing pages) is allowed. Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to modfiy this document
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsEditNotesAllowed (  )  const [inline]

Checks if it is allowed to add or modify annotations or form fields Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to add or modify annotations or form fields
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsFillAndSignAllowed (  )  const [inline]

Checks if it is allowed to fill in existing form or signature fields Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to fill in existing form or signature fields
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsHighPrintAllowed (  )  const [inline]

Checks if it is allowed to print a high quality version of this document Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to print a high quality version of this document
See also:
PdfEncrypt to set own document permissions.

bool PoDoFo::PdfEncrypt::IsPrintAllowed (  )  const [inline]

Checks if printing this document is allowed. Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to print this document
See also:
PdfEncrypt to set own document permissions.

const PdfEncrypt & PoDoFo::PdfEncrypt::operator= ( const PdfEncrypt rhs  ) 

Assignment operator

Parameters:
rhs another PdfEncrypt object which is copied

void PoDoFo::PdfEncrypt::RC4 ( unsigned char *  key,
int  keylen,
unsigned char *  textin,
int  textlen,
unsigned char *  textout 
) [protected]

RC4 encryption.

RC4 is the standard encryption algorithm used in PDF format

void PoDoFo::PdfEncrypt::SetCurrentReference ( const PdfReference rRef  )  [inline]

Set the reference of the object that is currently encrypted.

This value will be used in following calls of Encrypt to encrypt the object.

See also:
Encrypt


Generated on Mon Aug 17 13:47:21 2009 for PoDoFo by  doxygen 1.5.9