wxPdfDocument 1.2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
wxPdfEncrypt Class Reference

Class representing PDF encryption methods. (For internal use only) More...

#include <pdfencrypt.h>

Public Member Functions

 wxPdfEncrypt (int revision=2, int keyLength=40)
 Constructor.
 
virtual ~wxPdfEncrypt ()
 Default destructor.
 
void GenerateEncryptionKey (const wxString &userPassword, const wxString &ownerPassword, int protection, const wxString &documentId=wxEmptyString)
 Generate encryption key from user and owner passwords and protection key.
 
bool Authenticate (const wxString &documentID, const wxString &password, const wxString &uValue, const wxString &oValue, const wxString &ueValue, const wxString &oeValue, const wxString &permsValue, int pValue, int lengthValue, int rValue, int vValue)
 Authenticate a document.
 
bool PasswordIsValid (const wxString &password) const
 
const std::string & GetUValue () const
 Get the U object value (user)
 
const std::string & GetUEValue () const
 Get the UE object value (user)
 
const std::string & GetOValue () const
 Get the O object value (owner)
 
const std::string & GetOEValue () const
 Get the OE object value (owner)
 
int GetPValue () const
 Get the P object value (protection)
 
const std::string & GetPermsValue () const
 Get the Perms object value (protection)
 
int GetRevision () const
 Get the revision number of the encryption method.
 
unsigned int GetKeyLength () const
 Get the key length of the encryption key in bits.
 
void Encrypt (int n, int g, wxString &str)
 Encrypt a wxString.
 
void Decrypt (int n, int g, wxString &str)
 Decrypt a wxString.
 
void Encrypt (int n, int g, unsigned char *str, unsigned int len)
 Encrypt a character string.
 
int Decrypt (int n, int g, unsigned char *str, unsigned int len)
 Decrypt a character string.
 
size_t CalculateStreamLength (size_t length)
 Calculate stream size.
 
size_t CalculateStreamOffset ()
 Calculate stream offset.
 
wxString GetDocumentId () const
 Get document id.
 

Static Public Member Functions

static wxString CreateDocumentId ()
 Create document id.
 

Protected Member Functions

std::string PadPassword (const wxString &password)
 Pad a password to 32 characters.
 
std::string ComputeOwnerKey (const std::string &userPad, const std::string &ownerPad, unsigned int keylength, int revision, bool authenticate)
 Compute owner key.
 
std::string ComputeEncryptionKey (const wxString &documentID, const std::string &userPad, const std::string &ownerKey, int pValue, unsigned int keyLength, int revision)
 Compute encryption key and user key.
 
bool CheckKey (const std::string &key1, const std::string &key2)
 Check two keys for equality.
 
void RC4 (unsigned char *key, unsigned int keylen, const unsigned char *textin, unsigned int textlen, unsigned char *textout)
 RC4 encryption.
 
void AESEncrypt (unsigned char *key, unsigned int keylen, unsigned char *textin, unsigned int textlen, unsigned char *textout)
 AES-128 encryption.
 
int AESDecrypt (unsigned char *key, unsigned int keylen, unsigned char *textin, unsigned int textlen, unsigned char *textout)
 AES-128 decryption.
 
void AESV3Encrypt (const unsigned char *key, unsigned int keylen, const unsigned char *textin, unsigned int textlen, unsigned char *textout)
 AES-256 encryption.
 
int AESV3Decrypt (const unsigned char *key, unsigned int keylen, unsigned char *textin, unsigned int textlen, unsigned char *textout)
 AES-256 decryption.
 

Static Protected Member Functions

static void GetMD5Binary (const unsigned char *data, unsigned int length, unsigned char *digest)
 Calculate the binary MD5 message digest of the given data.
 
static void GenerateInitialVector (unsigned char iv[16])
 Generate initial vector.
 

Detailed Description

Class representing PDF encryption methods. (For internal use only)

Constructor & Destructor Documentation

◆ wxPdfEncrypt()

wxPdfEncrypt::wxPdfEncrypt ( int revision = 2,
int keyLength = 40 )

Constructor.

Parameters
revisionrevision of the encryption algorithm
keyLengthlength of the key for the encryption

◆ ~wxPdfEncrypt()

virtual wxPdfEncrypt::~wxPdfEncrypt ( )
virtual

Default destructor.

Member Function Documentation

◆ AESDecrypt()

int wxPdfEncrypt::AESDecrypt ( unsigned char * key,
unsigned int keylen,
unsigned char * textin,
unsigned int textlen,
unsigned char * textout )
protected

AES-128 decryption.

◆ AESEncrypt()

void wxPdfEncrypt::AESEncrypt ( unsigned char * key,
unsigned int keylen,
unsigned char * textin,
unsigned int textlen,
unsigned char * textout )
protected

AES-128 encryption.

◆ AESV3Decrypt()

int wxPdfEncrypt::AESV3Decrypt ( const unsigned char * key,
unsigned int keylen,
unsigned char * textin,
unsigned int textlen,
unsigned char * textout )
protected

AES-256 decryption.

◆ AESV3Encrypt()

void wxPdfEncrypt::AESV3Encrypt ( const unsigned char * key,
unsigned int keylen,
const unsigned char * textin,
unsigned int textlen,
unsigned char * textout )
protected

AES-256 encryption.

◆ Authenticate()

bool wxPdfEncrypt::Authenticate ( const wxString & documentID,
const wxString & password,
const wxString & uValue,
const wxString & oValue,
const wxString & ueValue,
const wxString & oeValue,
const wxString & permsValue,
int pValue,
int lengthValue,
int rValue,
int vValue )

Authenticate a document.

Parameters
documentIDthe identification of the document
passwordthe password given by the user
uValuethe U value from the document's encryption dictionary
oValuethe O value from the document's encryption dictionary
ueValuethe UE value from the document's encryption dictionary
oeValuethe OE value from the document's encryption dictionary
permsValuethe Perms value from the document's encryption dictionary
pValuethe P value from the document's encryption dictionary
lengthValuethe length value from the document's encryption dictionary
rValuethe R value from the document's encryption dictionary
vValuethe V value from the document's encryption dictionary
Returns
TRUE if the document could be authenticated successfully, FALSE otherwise

◆ CalculateStreamLength()

size_t wxPdfEncrypt::CalculateStreamLength ( size_t length)

Calculate stream size.

Parameters
lengthlength of the original stream
Returns
the length of the encrypted stream

◆ CalculateStreamOffset()

size_t wxPdfEncrypt::CalculateStreamOffset ( )

Calculate stream offset.

Returns
the offset of the stream

◆ CheckKey()

bool wxPdfEncrypt::CheckKey ( const std::string & key1,
const std::string & key2 )
protected

Check two keys for equality.

◆ ComputeEncryptionKey()

std::string wxPdfEncrypt::ComputeEncryptionKey ( const wxString & documentID,
const std::string & userPad,
const std::string & ownerKey,
int pValue,
unsigned int keyLength,
int revision )
protected

Compute encryption key and user key.

◆ ComputeOwnerKey()

std::string wxPdfEncrypt::ComputeOwnerKey ( const std::string & userPad,
const std::string & ownerPad,
unsigned int keylength,
int revision,
bool authenticate )
protected

Compute owner key.

◆ CreateDocumentId()

static wxString wxPdfEncrypt::CreateDocumentId ( )
static

Create document id.

Returns
the created document identifier

◆ Decrypt() [1/2]

int wxPdfEncrypt::Decrypt ( int n,
int g,
unsigned char * str,
unsigned int len )

Decrypt a character string.

Parameters
nnumber of the associated PDF object
ggeneration of the associated PDF object
strstring to decrypt
lenlength of the string to decrypt

◆ Decrypt() [2/2]

void wxPdfEncrypt::Decrypt ( int n,
int g,
wxString & str )

Decrypt a wxString.

Parameters
nnumber of the associated PDF object
ggeneration of the associated PDF object
strstring to decrypt

◆ Encrypt() [1/2]

void wxPdfEncrypt::Encrypt ( int n,
int g,
unsigned char * str,
unsigned int len )

Encrypt a character string.

Parameters
nnumber of the associated PDF object
ggeneration of the associated PDF object
strstring to encrypt
lenlength of the string to encrypt

◆ Encrypt() [2/2]

void wxPdfEncrypt::Encrypt ( int n,
int g,
wxString & str )

Encrypt a wxString.

Parameters
nnumber of the associated PDF object
ggeneration of the associated PDF object
strstring to encrypt

◆ GenerateEncryptionKey()

void wxPdfEncrypt::GenerateEncryptionKey ( const wxString & userPassword,
const wxString & ownerPassword,
int protection,
const wxString & documentId = wxEmptyString )

Generate encryption key from user and owner passwords and protection key.

Parameters
userPasswordpassword of the user
ownerPasswordpassword of the owner
protectionprotection flags
documentIdoptional document identification

◆ GenerateInitialVector()

static void wxPdfEncrypt::GenerateInitialVector ( unsigned char iv[16])
staticprotected

Generate initial vector.

◆ GetDocumentId()

wxString wxPdfEncrypt::GetDocumentId ( ) const
inline

Get document id.

Returns
the associated document identifier

◆ GetKeyLength()

unsigned int wxPdfEncrypt::GetKeyLength ( ) const
inline

Get the key length of the encryption key in bits.

◆ GetMD5Binary()

static void wxPdfEncrypt::GetMD5Binary ( const unsigned char * data,
unsigned int length,
unsigned char * digest )
staticprotected

Calculate the binary MD5 message digest of the given data.

◆ GetOEValue()

const std::string & wxPdfEncrypt::GetOEValue ( ) const
inline

Get the OE object value (owner)

◆ GetOValue()

const std::string & wxPdfEncrypt::GetOValue ( ) const
inline

Get the O object value (owner)

◆ GetPermsValue()

const std::string & wxPdfEncrypt::GetPermsValue ( ) const
inline

Get the Perms object value (protection)

◆ GetPValue()

int wxPdfEncrypt::GetPValue ( ) const
inline

Get the P object value (protection)

◆ GetRevision()

int wxPdfEncrypt::GetRevision ( ) const
inline

Get the revision number of the encryption method.

◆ GetUEValue()

const std::string & wxPdfEncrypt::GetUEValue ( ) const
inline

Get the UE object value (user)

◆ GetUValue()

const std::string & wxPdfEncrypt::GetUValue ( ) const
inline

Get the U object value (user)

◆ PadPassword()

std::string wxPdfEncrypt::PadPassword ( const wxString & password)
protected

Pad a password to 32 characters.

◆ PasswordIsValid()

bool wxPdfEncrypt::PasswordIsValid ( const wxString & password) const

◆ RC4()

void wxPdfEncrypt::RC4 ( unsigned char * key,
unsigned int keylen,
const unsigned char * textin,
unsigned int textlen,
unsigned char * textout )
protected

RC4 encryption.


The documentation for this class was generated from the following file: