Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Document::encrypt() #396

Merged
merged 13 commits into from
Mar 1, 2025
Merged

Conversation

StephanvanSchaik
Copy link
Contributor

Since this pull request is getting quite large already, I am leaving the work of implementing more sanity checks in terms of what is possible depending on the version/revision, actual test cases and an EncryptionStateBuilder when creating new PDF documents for the next pull request, but I think those are the tasks that are currently left to do.

This pull request implements Document::encrypt().

The EncryptionState has been reworked to store all the relevant pieces of information from the encrypted dictionary, that way we can encode it back to an encrypted dictionary when encrypting it. The decoding logic has also been moved into EncryptionState::decode(). In addition, some fixes were required to make this work such as storing the default stream/string crypt filters by name and adding CryptFilter::method() which returns the name to be stored in the CFM field.

This pull request also implements the remaining algorithms to compute the owner values, user values and permissions for revision 6 as well as the algorithm to verify the permissions. Part of which will become relevant for the EncryptionStateBuilder.

Most of the other commits clean up the code a bit here and there.

Document::encrypt() uses EncryptionState::encode() to create the encrypted dictionary and store it in the trailer of the documents and proceeds to use encrypt_object() to encrypts the stream/string objects.

@J-F-Liu J-F-Liu merged commit e566664 into J-F-Liu:main Mar 1, 2025
7 checks passed
@StephanvanSchaik StephanvanSchaik deleted the encryption-v3 branch March 1, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants