PoDoFo 0.9.20
PoDoFo::PdfEncrypt Class Referenceabstract

#include <PdfEncrypt.h>

Public Member Functions

void GenerateEncryptionKey (const PdfString &documentId)
 
virtual void CreateEncryptionDictionary (PdfDictionary &dictionary) const =0
 
virtual std::unique_ptr< InputStreamCreateEncryptionInputStream (InputStream &inputStream, size_t inputLen, const PdfReference &objref)=0
 
virtual std::unique_ptr< OutputStreamCreateEncryptionOutputStream (OutputStream &outputStream, const PdfReference &objref)=0
 
bool Authenticate (const std::string_view &password, const PdfString &documentId)
 
PdfEncryptAlgorithm GetEncryptAlgorithm () const
 
bool IsOwnerPasswordSet () 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
 
const unsigned char * GetOValue () const
 
const unsigned char * GetEncryptionKey () const
 
PdfPermissions GetPValue () const
 
int GetRevision () const
 
int GetKeyLength () const
 
bool IsMetadataEncrypted () const
 
void EncryptTo (charbuff &out, const bufferview &view, const PdfReference &objref) const
 
void DecryptTo (charbuff &out, const bufferview &view, const PdfReference &objref) const
 
virtual size_t CalculateStreamLength (size_t length) const =0
 
virtual size_t CalculateStreamOffset () const =0
 

Static Public Member Functions

static std::unique_ptr< PdfEncryptCreate (const std::string_view &userPassword, const std::string_view &ownerPassword, PdfPermissions protection=PdfPermissions::Default, PdfEncryptAlgorithm algorithm=PdfEncryptAlgorithm::AESV2, PdfKeyLength keyLength=PdfKeyLength::L40)
 
static std::unique_ptr< PdfEncryptCreateFromObject (const PdfObject &obj)
 
static std::unique_ptr< PdfEncryptCreateFromEncrypt (const PdfEncrypt &rhs)
 
static PdfEncryptAlgorithm GetEnabledEncryptionAlgorithms ()
 
static void SetEnabledEncryptionAlgorithms (PdfEncryptAlgorithm nEncryptionAlgorithms)
 
static bool IsEncryptionEnabled (PdfEncryptAlgorithm algorithm)
 

Detailed Description

A class that is used to encrypt a PDF file and set document permissions on the PDF file.

As a user of this class, you have only to instantiate 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 Function Documentation

◆ Authenticate()

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

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

◆ CalculateStreamLength()

virtual size_t PoDoFo::PdfEncrypt::CalculateStreamLength ( size_t length) const
pure virtual

Calculate stream size

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

◆ CalculateStreamOffset()

virtual size_t PoDoFo::PdfEncrypt::CalculateStreamOffset ( ) const
pure virtual

Calculate stream offset

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

◆ Create()

unique_ptr< PdfEncrypt > PdfEncrypt::Create ( const std::string_view & userPassword,
const std::string_view & ownerPassword,
PdfPermissions protection = PdfPermissions::Default,
PdfEncryptAlgorithm algorithm = PdfEncryptAlgorithm::AESV2,
PdfKeyLength keyLength = PdfKeyLength::L40 )
static

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

Parameters
userPasswordthe user password (if empty the user does not have to enter a password to open the document)
ownerPasswordthe owner password
protectionseveral PdfPermissions values or'ed together to set the users permissions for this document
algorithmthe revision of the encryption algorithm to be used
keyLengththe length of the encryption key ranging from 40 to 128 bits (only used if algorithm == PdfEncryptAlgorithm::RC4V2)
See also
GenerateEncryptionKey with the documentID to generate the real encryption key using this information

◆ CreateEncryptionDictionary()

virtual void PoDoFo::PdfEncrypt::CreateEncryptionDictionary ( PdfDictionary & dictionary) 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
dictionaryan empty dictionary which is filled with information about the used encryption algorithm

◆ CreateEncryptionInputStream()

virtual std::unique_ptr< InputStream > PoDoFo::PdfEncrypt::CreateEncryptionInputStream ( InputStream & inputStream,
size_t inputLen,
const PdfReference & objref )
pure virtual

Create an InputStream 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
inputStreamthe created InputStream reads all decrypted data to this input stream.
Returns
an InputStream that decrypts all data.

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

◆ CreateEncryptionOutputStream()

virtual std::unique_ptr< OutputStream > PoDoFo::PdfEncrypt::CreateEncryptionOutputStream ( OutputStream & outputStream,
const PdfReference & objref )
pure virtual

Create an OutputStream 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
outputStreamthe created OutputStream writes all encrypted data to this output stream.
Returns
a OutputStream that encrypts all data.

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

◆ CreateFromEncrypt()

unique_ptr< PdfEncrypt > PdfEncrypt::CreateFromEncrypt ( const PdfEncrypt & rhs)
static

Copy constructor

Parameters
rhsanother PdfEncrypt object which is copied

◆ CreateFromObject()

unique_ptr< PdfEncrypt > PdfEncrypt::CreateFromObject ( const PdfObject & obj)
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.

Will use only encrypting algorithms that are enabled.

Parameters
obja PDF encryption dictionary
See also
GetEnabledEncryptionAlgorithms

◆ DecryptTo()

void PdfEncrypt::DecryptTo ( charbuff & out,
const bufferview & view,
const PdfReference & objref ) const

Decrypt a character span

◆ EncryptTo()

void PdfEncrypt::EncryptTo ( charbuff & out,
const bufferview & view,
const PdfReference & objref ) const

Encrypt a character span

◆ GenerateEncryptionKey()

void PdfEncrypt::GenerateEncryptionKey ( const PdfString & documentId)

Generate encryption key from user and owner passwords and protection key

Parameters
documentIdthe documentId of the current document

◆ GetEnabledEncryptionAlgorithms()

PdfEncryptAlgorithm PdfEncrypt::GetEnabledEncryptionAlgorithms ( )
static

Retrieve the list of encryption algorithms that are used when loading a PDF document.

By default all algorithms are enabled.

See also
IsEncryptionEnabled
SetEnabledEncryptionAlgorithms
Returns
an or'ed together list of all enabled encryption algorithms

◆ GetEncryptAlgorithm()

PdfEncryptAlgorithm PoDoFo::PdfEncrypt::GetEncryptAlgorithm ( ) const
inline

Get the encryption algorithm of this object.

Returns
the PdfEncryptAlgorithm of this object

◆ GetEncryptionKey()

const unsigned char * PoDoFo::PdfEncrypt::GetEncryptionKey ( ) const
inline

Get the encryption key value (owner)

◆ GetKeyLength()

int PdfEncrypt::GetKeyLength ( ) const

Get the key length of the encryption key in bits

◆ GetOValue()

const unsigned char * PoDoFo::PdfEncrypt::GetOValue ( ) const
inline

Get the O object value (owner)

◆ GetPValue()

PdfPermissions PoDoFo::PdfEncrypt::GetPValue ( ) const
inline

Get the P object value (protection)

◆ GetRevision()

int PoDoFo::PdfEncrypt::GetRevision ( ) const
inline

Get the revision number of the encryption method

◆ GetUValue()

const unsigned char * PoDoFo::PdfEncrypt::GetUValue ( ) const
inline

Get the U object value (user)

◆ IsAccessibilityAllowed()

bool PdfEncrypt::IsAccessibilityAllowed ( ) const

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

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

◆ IsCopyAllowed()

bool PdfEncrypt::IsCopyAllowed ( ) const

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.

◆ IsDocAssemblyAllowed()

bool PdfEncrypt::IsDocAssemblyAllowed ( ) const

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.

◆ IsEditAllowed()

bool PdfEncrypt::IsEditAllowed ( ) const

Checks if modifying 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 modify this document
See also
PdfEncrypt to set own document permissions.

◆ IsEditNotesAllowed()

bool PdfEncrypt::IsEditNotesAllowed ( ) const

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.

◆ IsEncryptionEnabled()

bool PdfEncrypt::IsEncryptionEnabled ( PdfEncryptAlgorithm algorithm)
static

Test if a certain encryption algorithm is enabled for loading PDF documents.

Returns
true if the encryption algorithm is enabled
See also
GetEnabledEncryptionAlgorithms
SetEnabledEncryptionAlgorithms

◆ IsFillAndSignAllowed()

bool PdfEncrypt::IsFillAndSignAllowed ( ) const

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.

◆ IsHighPrintAllowed()

bool PdfEncrypt::IsHighPrintAllowed ( ) const

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.

◆ IsMetadataEncrypted()

bool PoDoFo::PdfEncrypt::IsMetadataEncrypted ( ) const
inline

Is metadata encrypted

◆ IsOwnerPasswordSet()

bool PoDoFo::PdfEncrypt::IsOwnerPasswordSet ( ) const
inline

Checks if an owner password is set. An application reading PDF must adhere to permissions for printing, copying, etc., unless the owner password was used to open it.

Returns
true if the owner password is set, in which case IsPrintAllowed etc. should be ignored
See also
PdfEncrypt to set own document permissions.

◆ IsPrintAllowed()

bool PdfEncrypt::IsPrintAllowed ( ) const

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.

◆ SetEnabledEncryptionAlgorithms()

void PdfEncrypt::SetEnabledEncryptionAlgorithms ( PdfEncryptAlgorithm nEncryptionAlgorithms)
static

Specify the list of encryption algorithms that should be used by PoDoFo when loading a PDF document.

This can be used to disable for example AES encryption/decryption which is unstable in certain cases.

See also
GetEnabledEncryptionAlgorithms
IsEncryptionEnabled