PoDoFo
1.0.0-dev
|
A class that is used to encrypt a PDF file and set document permissions on the PDF file. More...
#include <PdfEncrypt.h>
Inherited by PoDoFo::PdfEncryptMD5Base.
Public Member Functions | |
void | EnsureEncryptionInitialized (const PdfString &documentId, PdfEncryptContext &context) |
Ensure encryption key and /O, /U, /OE, /UE values are initialized. More... | |
void | Authenticate (const std::string_view &password, const PdfString &documentId, PdfEncryptContext &context) const |
Tries to authenticate a user using either the user or owner password. More... | |
virtual void | CreateEncryptionDictionary (PdfDictionary &dictionary) const =0 |
Fill all keys into a encryption dictionary. More... | |
virtual std::unique_ptr< InputStream > | CreateEncryptionInputStream (InputStream &inputStream, size_t inputLen, PdfEncryptContext &context, const PdfReference &objref) const =0 |
Create an InputStream that decrypts all data read from it using the current settings of the PdfEncrypt object. More... | |
virtual std::unique_ptr< OutputStream > | CreateEncryptionOutputStream (OutputStream &outputStream, PdfEncryptContext &context, const PdfReference &objref) const =0 |
Create an OutputStream that encrypts all data written to it using the current settings of the PdfEncrypt object. More... | |
PdfEncryptionAlgorithm | GetEncryptAlgorithm () const |
Get the encryption algorithm of this object. More... | |
bool | IsOwnerPasswordSet () const |
Checks if an owner password is set. More... | |
bool | IsPrintAllowed () const |
Checks if printing this document is allowed. More... | |
bool | IsEditAllowed () const |
Checks if modifying this document (besides annotations, form fields or changing pages) is allowed. More... | |
bool | IsCopyAllowed () const |
Checks if text and graphics extraction is allowed. More... | |
bool | IsEditNotesAllowed () const |
Checks if it is allowed to add or modify annotations or form fields Every PDF consuming applications has to adhere this value! More... | |
bool | IsFillAndSignAllowed () const |
Checks if it is allowed to fill in existing form or signature fields Every PDF consuming applications has to adhere this value! More... | |
bool | 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! More... | |
bool | 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! More... | |
bool | 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! More... | |
void | EncryptTo (charbuff &out, const bufferview &view, PdfEncryptContext &context, const PdfReference &objref) const |
Encrypt a character span. | |
void | DecryptTo (charbuff &out, const bufferview &view, PdfEncryptContext &context, const PdfReference &objref) const |
Decrypt a character span. | |
virtual size_t | CalculateStreamLength (size_t length) const =0 |
Calculate stream size. | |
virtual size_t | CalculateStreamOffset () const =0 |
Calculate stream offset. | |
unsigned | GetKeyLengthBytes () const |
Get the encryption key length in bytes. More... | |
bufferview | GetUValue () const |
Get the U object value (user) | |
bufferview | GetOValue () const |
Get the O object value (owner) | |
PdfKeyLength | GetKeyLength () const |
Get the length of the encryption key in bits. | |
PdfPermissions | GetPValue () const |
Get the P object value (protection) | |
unsigned | GetRevision () const |
Get the revision number of the encryption method. | |
bool | IsMetadataEncrypted () const |
bool | IsParsed () const |
Static Public Member Functions | |
static std::unique_ptr< PdfEncrypt > | Create (const std::string_view &userPassword, const std::string_view &ownerPassword, PdfPermissions protection=PdfPermissions::Default, PdfEncryptionAlgorithm algorithm=PdfEncryptionAlgorithm::AESV2, PdfKeyLength keyLength=PdfKeyLength::Unknown) |
Create a PdfEncrypt object which can be used to encrypt a PDF file. More... | |
static std::unique_ptr< PdfEncrypt > | CreateFromObject (const PdfObject &obj) |
Initialize a PdfEncrypt object from an encryption dictionary in a PDF file. More... | |
static PdfEncryptionAlgorithm | GetEnabledEncryptionAlgorithms () |
Retrieve the list of encryption algorithms that are used when loading a PDF document. More... | |
static bool | IsEncryptionEnabled (PdfEncryptionAlgorithm algorithm) |
Test if a certain encryption algorithm is enabled for loading PDF documents. More... | |
Protected Types | |
enum class | PdfRC4Revision { R2 = 2 , R3 = 3 } |
Protected Member Functions | |
const unsigned char * | GetUValueRaw () const |
const unsigned char * | GetOValueRaw () const |
const std::string & | GetUserPassword () const |
const std::string & | GetOwnerPassword () const |
int64_t | GetPValueForSerialization () const |
void | InitFromValues (PdfEncryptionAlgorithm algorithm, PdfKeyLength keyLength, unsigned char revision, PdfPermissions pValue, const bufferview &uValue, const bufferview &oValue, bool encryptedMetadata) |
Init from parsed values. | |
void | InitFromScratch (const std::string_view &userPassword, const std::string_view &ownerPassword, PdfEncryptionAlgorithm algorithm, PdfKeyLength keyLength, unsigned char revision, PdfPermissions pValue, bool encryptedMetadata) |
Init from scratch with user/owner password. More... | |
virtual void | Decrypt (const char *inStr, size_t inLen, PdfEncryptContext &context, const PdfReference &objref, char *outStr, size_t &outLen) const =0 |
virtual void | Encrypt (const char *inStr, size_t inLen, PdfEncryptContext &context, const PdfReference &objref, char *outStr, size_t outLen) const =0 |
virtual PdfAuthResult | Authenticate (const std::string_view &password, const std::string_view &documentId, PODOFO_CRYPT_CTX *ctx, unsigned char encryptionKey[32]) const =0 |
virtual void | GenerateEncryptionKey (const std::string_view &documentId, PdfAuthResult authResult, PODOFO_CRYPT_CTX *ctx, unsigned char uValue[48], unsigned char oValue[48], unsigned char encryptionKey[32])=0 |
bool | CheckKey (const unsigned char key1[32], const unsigned char key2[32]) const |
Friends | |
class | PdfEncryptMD5Base |
class | PdfEncryptAESV3 |
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.
void PoDoFo::PdfEncrypt::Authenticate | ( | const std::string_view & | password, |
const PdfString & | documentId, | ||
PdfEncryptContext & | context | ||
) | const |
Tries to authenticate a user using either the user or owner password.
password | owner or user password |
documentId | the documentId of the PDF file |
|
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::PdfEncryptRC4, and PoDoFo::PdfEncryptAESV2.
|
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::PdfEncryptRC4, and PoDoFo::PdfEncryptAESV2.
|
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::EnsureEncryptionInitialized | ( | const PdfString & | documentId, |
PdfEncryptContext & | context | ||
) |
Ensure encryption key and /O, /U, /OE, /UE values are initialized.
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.
unsigned PdfEncrypt::GetKeyLengthBytes | ( | ) | const |
Get the encryption key length in bytes.
|
protected |
Init from scratch with user/owner password.
Requires full initialization with EnsureEncryptionInitialized
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!
bool PdfEncrypt::IsOwnerPasswordSet | ( | ) | const |
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!