PoDoFo 0.9.20
|
#include <PdfEncrypt.h>
Public Member Functions | |
void | GenerateEncryptionKey (const PdfString &documentId) |
virtual void | CreateEncryptionDictionary (PdfDictionary &dictionary) const =0 |
virtual std::unique_ptr< InputStream > | CreateEncryptionInputStream (InputStream &inputStream, size_t inputLen, const PdfReference &objref)=0 |
virtual std::unique_ptr< OutputStream > | CreateEncryptionOutputStream (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< 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 std::unique_ptr< PdfEncrypt > | CreateFromObject (const PdfObject &obj) |
static std::unique_ptr< PdfEncrypt > | CreateFromEncrypt (const PdfEncrypt &rhs) |
static PdfEncryptAlgorithm | GetEnabledEncryptionAlgorithms () |
static void | SetEnabledEncryptionAlgorithms (PdfEncryptAlgorithm nEncryptionAlgorithms) |
static bool | IsEncryptionEnabled (PdfEncryptAlgorithm algorithm) |
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.
bool PoDoFo::PdfEncrypt::Authenticate | ( | const std::string_view & | password, |
const PdfString & | documentId ) |
Tries to authenticate a user using either the user or owner password
password | owner or user password |
documentId | the documentId of the PDF file |
|
pure virtual |
Calculate stream size
Implemented in PoDoFo::PdfEncryptAESV2, and PoDoFo::PdfEncryptRC4.
|
pure virtual |
Calculate stream offset
Implemented in PoDoFo::PdfEncryptAESV2, and PoDoFo::PdfEncryptRC4.
|
static |
Create a PdfEncrypt object which can be used to encrypt a PDF file.
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 PdfPermissions values or'ed together to set the users permissions for this document |
algorithm | the revision of the encryption algorithm to be used |
keyLength | the length of the encryption key ranging from 40 to 128 bits (only used if algorithm == PdfEncryptAlgorithm::RC4V2) |
|
pure virtual |
Fill all keys into a encryption dictionary. This dictionary is usually added to the PDF files trailer under the /Encryption key.
dictionary | an empty dictionary which is filled with information about the used encryption algorithm |
|
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!
inputStream | the created InputStream reads all decrypted data to this input stream. |
Implemented in PoDoFo::PdfEncryptAESV2, and PoDoFo::PdfEncryptRC4.
|
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!
outputStream | the created OutputStream writes all encrypted data to this output stream. |
Implemented in PoDoFo::PdfEncryptAESV2, and PoDoFo::PdfEncryptRC4.
|
static |
Copy constructor
rhs | another PdfEncrypt object which is copied |
|
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.
obj | a PDF encryption dictionary |
void PdfEncrypt::DecryptTo | ( | charbuff & | out, |
const bufferview & | view, | ||
const PdfReference & | objref ) const |
Decrypt a character span
void PdfEncrypt::EncryptTo | ( | charbuff & | out, |
const bufferview & | view, | ||
const PdfReference & | objref ) const |
Encrypt a character span
void PdfEncrypt::GenerateEncryptionKey | ( | const PdfString & | documentId | ) |
Generate encryption key from user and owner passwords and protection key
documentId | the documentId of the current document |
|
static |
Retrieve the list of encryption algorithms that are used when loading a PDF document.
By default all algorithms are enabled.
|
inline |
Get the encryption algorithm of this object.
|
inline |
Get the encryption key value (owner)
int PdfEncrypt::GetKeyLength | ( | ) | const |
Get the key length of the encryption key in bits
|
inline |
Get the O object value (owner)
|
inline |
Get the P object value (protection)
|
inline |
Get the revision number of the encryption method
|
inline |
Get the U object value (user)
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!
bool PdfEncrypt::IsCopyAllowed | ( | ) | const |
Checks if text and graphics extraction is allowed. Every PDF consuming applications has to adhere this value!
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!
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!
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!
|
static |
Test if a certain encryption algorithm is enabled for loading PDF documents.
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!
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!
|
inline |
Is metadata encrypted
|
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.
bool PdfEncrypt::IsPrintAllowed | ( | ) | const |
Checks if printing this document is allowed. Every PDF consuming applications has to adhere this value!
|
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.