PoDoFo  0.9.1
Public Member Functions | List of all members
PoDoFo::PdfEncryptAESV2 Class Reference

#include <PdfEncrypt.h>

Inheritance diagram for PoDoFo::PdfEncryptAESV2:
PoDoFo::PdfEncryptAESBase

Public Member Functions

virtual PdfInputStreamCreateEncryptionInputStream (PdfInputStream *pInputStream)
 
virtual PdfOutputStreamCreateEncryptionOutputStream (PdfOutputStream *pOutputStream)
 
virtual bool Authenticate (const std::string &password, const PdfString &documentId)
 
virtual void Encrypt (const unsigned char *inStr, pdf_long inLen, unsigned char *outStr, pdf_long outLen) const
 Encrypt a character string.
 
virtual void Decrypt (const unsigned char *inStr, pdf_long inLen, unsigned char *outStr, pdf_long outLen) const
 Decrypt a character string.
 
virtual void GenerateEncryptionKey (const PdfString &documentId)
 
virtual pdf_long CalculateStreamOffset () const
 Calculate stream offset.
 
virtual pdf_long CalculateStreamLength (pdf_long length) const
 Calculate stream size.
 
- Public Member Functions inherited from PoDoFo::PdfEncryptMD5Base
virtual void Encrypt (const unsigned char *inStr, pdf_long inLen, unsigned char *outStr, pdf_long outLen) const =0
 Encrypt a character string.
 
- Public Member Functions inherited from PoDoFo::PdfEncrypt
virtual ~PdfEncrypt ()=0
 
virtual void CreateEncryptionDictionary (PdfDictionary &rDictionary) const =0
 
EPdfEncryptAlgorithm GetEncryptAlgorithm () const
 
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)
 
const unsigned char * GetEncryptionKey () const
 Get the encryption key value (owner)
 
pdf_int32 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 SetCurrentReference (const PdfReference &rRef)
 

Additional Inherited Members

- Public Types inherited from PoDoFo::PdfEncrypt
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 = 1, ePdfEncryptAlgorithm_RC4V2 = 2, ePdfEncryptAlgorithm_AESV2 = 4 }
 
- Static Public Member Functions inherited from PoDoFo::PdfEncryptMD5Base
static PdfString GetMD5String (const unsigned char *pBuffer, int nLength)
 
static void GetMD5Binary (const unsigned char *data, int length, unsigned char *digest)
 Calculate the binary MD5 message digest of the given data.
 
- Static Public Member Functions inherited from PoDoFo::PdfEncrypt
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 int GetEnabledEncryptionAlgorithms ()
 
static void SetEnabledEncryptionAlgorithms (int nEncryptionAlgorithms)
 
static bool IsEncryptionEnabled (EPdfEncryptAlgorithm eAlgorithm)
 
- Protected Member Functions inherited from PoDoFo::PdfEncryptMD5Base
virtual void GenerateInitialVector (unsigned char iv[16])
 Generate initial vector.
 
void ComputeOwnerKey (unsigned char userPad[32], unsigned char ownerPad[32], int keylength, int revision, bool authenticate, unsigned char ownerKey[32])
 Compute owner key.
 
void PadPassword (const std::string &password, unsigned char pswd[32])
 Pad a password to 32 characters.
 
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.
 
virtual void CreateObjKey (unsigned char objkey[16], int *pnKeyLen) const
 
- Protected Member Functions inherited from PoDoFo::PdfEncrypt
bool CheckKey (unsigned char key1[32], unsigned char key2[32])
 Check two keys for equality.
 
- Protected Member Functions inherited from PoDoFo::PdfEncryptRC4Base
void RC4 (const unsigned char *key, int keylen, const unsigned char *textin, pdf_long textlen, unsigned char *textout, pdf_long textoutlen)
 AES encryption. More...
 
- Protected Member Functions inherited from PoDoFo::PdfEncryptAESBase
void AES (const unsigned char *key, int keylen, const unsigned char *iv, const unsigned char *textin, pdf_long textlen, unsigned char *textout, pdf_long textoutlen)
 AES encryption.
 
- Protected Attributes inherited from PoDoFo::PdfEncryptMD5Base
unsigned char m_rc4key [16]
 last RC4 key
 
unsigned char m_rc4last [256]
 last RC4 state table
 
- Protected Attributes inherited from PoDoFo::PdfEncrypt
EPdfEncryptAlgorithm m_eAlgorithm
 The used encryption algorithm.
 
int m_keyLength
 Length of encryption key.
 
int m_rValue
 Revision.
 
pdf_int32 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_uValue [48]
 U entry in pdf document.
 
unsigned char m_oValue [48]
 O entry in pdf document.
 
unsigned char m_encryptionKey [32]
 Encryption key.
 
PdfReference m_curReference
 Reference of the current PdfObject.
 
std::string m_documentId
 DocumentID of the current document.
 
- Protected Attributes inherited from PoDoFo::PdfEncryptRC4Base
RC4CryptoEngine * m_rc4
 AES encryptor.
 
- Protected Attributes inherited from PoDoFo::PdfEncryptAESBase
AESCryptoEngine * m_aes
 AES encryptor.
 

Detailed Description

A class that is used to encrypt a PDF file (AES-128)

Client code is working only with PdfEncrypt class and knows nothing about PdfEncryptAES*, it is created through CreatePdfEncrypt factory method

Member Function Documentation

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

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

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

Implements PoDoFo::PdfEncrypt.

PdfInputStream * PoDoFo::PdfEncryptAESV2::CreateEncryptionInputStream ( PdfInputStream pInputStream)
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
pInputStreamthe created PdfInputStream reads all decrypted data to this input stream.
Returns
a PdfInputStream that decrypts all data.

Implements PoDoFo::PdfEncrypt.

PdfOutputStream * PoDoFo::PdfEncryptAESV2::CreateEncryptionOutputStream ( PdfOutputStream pOutputStream)
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
pOutputStreamthe created PdfOutputStream writes all encrypted data to this output stream.
Returns
a PdfOutputStream that encryts all data.

Implements PoDoFo::PdfEncrypt.

void PoDoFo::PdfEncryptAESV2::GenerateEncryptionKey ( const PdfString documentId)
virtual

Generate encryption key from user and owner passwords and protection key

Parameters
documentIdthe documentId of the current document

Implements PoDoFo::PdfEncrypt.